数据库里有这样一个表cards
batchid status createdate
batchid表示批次,status里1表示停用,2表示正常,createdate表示创建时间现在想输出一个表格,每行显示一个批次的信息,要求查询 '2005-12-12' < createdate < '2010-12-12'时间段中 status = 1的有多少张(count(*)),status = 2的各有多少张
举例为
批号 正常卡 停用卡
34 150 20
35 79 11
......
batchid status createdate
batchid表示批次,status里1表示停用,2表示正常,createdate表示创建时间现在想输出一个表格,每行显示一个批次的信息,要求查询 '2005-12-12' < createdate < '2010-12-12'时间段中 status = 1的有多少张(count(*)),status = 2的各有多少张
举例为
批号 正常卡 停用卡
34 150 20
35 79 11
......
解决方案 »
- SQL高手来解决100分
- 怎样把SQL Server的存储过程转移到ORACLE
- 存储过程下临时表多次使用 对象名无效 有好招?
- 视图跨服务器查询
- mssql2005监听端口1433没有启动
- 请教关于SQL的难题
- 请教
- 高分求救,如何从一个SELECT语句查询的数据集中再使用SELECT语句
- SQL企业版联接不上的问题
- (vfp6.0)列表框中有些文字太长了我希望当某个选项获得焦点时这些文字可以超出列表框长度突出显示请问应该怎样做?
- 请教一个简单的列复制问题(在线)
- *********************请问关于SQLSERVER 2005 EXPRESS的问题**********************
batchid as 批号,
sum(case status when 2 then 1 else 0 end) as 正常卡,
sum(case status when 1 then 1 else 0 end) as 停用卡
from
cards
where
createdate>'2005-12-12' and createdate<'2010-12-12'
group by
batchid
我这样写对是对,但感觉怪怪的
sum(case cardno when 1 then 1 else 1 end) as 总数
select
batchid as 批号,
sum(case status when 2 then 1 else 0 end) as 正常卡,
sum(case status when 1 then 1 else 0 end) as 停用卡,
count(cardno) as 总数
from
cards
where
createdate>'2005-12-12' and createdate<'2010-12-12'
group by
batchid
batchid as 批号,
sum(case status when 2 then 1 else 0 end) as 正常卡,
sum(case status when 1 then 1 else 0 end) as 停用卡,
count(cast(cardno as int)) as 总数
from
cards
where
createdate>'2005-12-12' and createdate<'2010-12-12'
group by
batchid