日期:2014-05-17 浏览次数:20664 次
declare @t table (id int,shuxue int,yuwen int)
insert into @t
select 1,50,30 union all
select 2,60,20 union all
select 3,70,30 union all
select 4,80,60 union all
select 5,90,70
select A='数学',jige=COUNT(1),bujige=((select COUNT(1) from @t)-COUNT(1)) from @t where shuxue>=60
union all
select A='语文',jige=COUNT(1),bujige=((select COUNT(1) from @t)-COUNT(1)) from @t where yuwen>=60
-----------------------------------------------
数学 4 1
语文 2 3
CREATE TABLE #Tmp_TABLE(编号 INT,数学 INT,语文 INT)
INSERT INTO #Tmp_TABLE
SELECT 1,50,30
UNION
SELECT 2,60,20
UNION
SELECT 3,70,30
UNION
SELECT 4,80,60
UNION
SELECT 5,90,70
SELECT
'数学' as 科目,
Sum(CASE WHEN 数学 >= 60 THEN 1 ELSE 0 END) AS '>=60分',
Sum(CASE WHEN 数学 < 60 THEN 1 ELSE 0 END) AS '<60分'
FROM #Tmp_TABLE
union all
SELECT
'语文' as 科目,
Sum(CASE WHEN 语文 >= 60 THEN 1 ELSE 0 END) AS '>=60分',
Sum(CASE WHEN 语文 < 60 THEN 1 ELSE 0 END) AS '<60分'