A. sql 查询 一个表中有科目、名字、状态三个字段, 怎么输出下面的结果(每个状态的人数)
select 科目, sum(case 状态 when '通过'then 1 else 0 end ) 通过,
sum(case 状态 when '不通过' then 1 else 0 end ) 不通过 ,
sum (case 状态 when '待定' then 1 else 0 end ) 待定
from table
group by 科目
B. SQL中查询有三个字段的记录相同的语句
select a.ID,a.NAME,a.SPC,a.UT from(select * from PRDT) as a,(select * from PRDT) as bwhere a.NAME=b.NAME and a.SPC=b.SPC and a.UT=b.UT and a.ID<>b.ID order by a.ID试试~
C. SQL Server 在查询结果增加自定义的三个字段如何搞
在后面加上如下语句:
(selectsum(sh.Precipitation)fromStationAwsh1f
wheref.StationId=sh.StationId
andf.ObservTimesBetweensh.ObservTimesand
replace(replace(convert(varchar(13),dateadd(hh,12,cast(left(sh.ObservTimes,8)+''+right(sh.ObservTimes,2)+':00'asdatetime)),120),'-',''),'','')
)asPre12H,
(selectsum(sh.Precipitation)fromStationAwsh1f
wheref.StationId=sh.StationId
andf.ObservTimesBetweensh.ObservTimesand
replace(replace(convert(varchar(13),dateadd(hh,24,cast(left(sh.ObservTimes,8)+''+right(sh.ObservTimes,2)+':00'asdatetime)),120),'-',''),'','')
)asPre24H,
(selectsum(sh.Precipitation)fromStationAwsh1f
wheref.StationId=sh.StationId
andf.ObservTimesBetweensh.ObservTimesand
replace(replace(convert(varchar(13),dateadd(hh,72,cast(left(sh.ObservTimes,8)+''+right(sh.ObservTimes,2)+':00'asdatetime)),120),'-',''),'','')
)asPre72H
D. 如何用SQL语句把现有3个表中的3个字段的所有组合方式创建一张新表
select sum(PICTURE)
from (
select count(PICTURE)*5 PICTURE from "DB2ADMIN"."C_NEWS" where PICTURE is not null
union all
select count(*)*5 DETAILS from "DB2ADMIN"."C_NEWS" where length(DETAILS)<1000 and="">0
union all
select count(*)*10 DETAILS from "DB2ADMIN"."C_NEWS" where length(DETAILS)>1000
) a