select count(*) from user where inputtime = '2012-12' group by type;
select count(*) from user wherer inputtime = to_date('2012-12','yyyy-mm') group by type 时间类型的字段需要转换
SELECT type,COUNT(*) FROM testTb GROUP BY type 判断时间方法每个数据库函数不一样
select * from (select count(*) as newsgnum from userg where time > '2012-01' and type='1') sg , (select count(*) as newjlnum from userg where time > '2012-01' and type='2') jl , (select count(*) as newjsnum from userg where time > '2012-01' and type='3') js , (select count(*) as newjcnum from userg where time > '2012-01' and type='4') jc , (select count(*) as newkcnum from userg where time > '2012-01' and type='5') kc , (select count(*) as newzxnum from userg where time > '2012-01' and type='6') zx , (select count(*) as newzbnum from userg where time > '2012-01' and type='7') zb , (select count(*) as newclnum from userg where time > '2012-01' and type='8') cl , (select count(*) as newbxnum from userg where time > '2012-01' and type='9') bx这是我写的一个语句。 能得到这样的结果 我想要的是能穿个时间实时的查处这些数字来。。 谢谢!
select sum(if(type=1,1,0))as newsgnum,sum(if(type=2,1,0))as newjlnum,sum(if(type=3,1,0))as newjsnum,sum(if(type=4,1,0))as newjcnum,sum(if(type=5,1,0))as newkcnum,sum(if(type=6,1,0))as newzxnum,sum(if(type=7,1,0))as newzbnum,sum(if(type=8,1,0))as newclnum,sum(if(type=9,1,0))as newbxnum from userg where time>'2012-01'
SELECT TRUNC(A.INPUTTYPE),TO_CHAR(A.TYPE) as TYPE,count(*) as count FROM TABLE A GROUP BY to_char(A.TYPE),TRUNC(A.CINPUTTIME) ;
请问lz是什么数据库 我写的是mysql的语法应该没问题
哦,不好意思,该早告诉你的 是sqlserver 2005。
你还是用这个吧 按顺序依次是type 1 - 9的值 需要你后台去联系上 SELECT type,COUNT(*) FROM userg GROUP BY type ORDER BY type ASC;
ORACLE 写的 写了3行 select sum(decode(type,1,cc,0)) as sg, select sum(decode(type,2,cc,0)) as jl, select sum(decode(type,3,cc,0)) as js from (select type, count(*) as cc from userg where time > '2012-01' group by type) 大致这样 比那个的效率应该要高一点,希望能帮到你
select count(*) from user where inputtime = '2012-12' group by type;
时间类型的字段需要转换
(select count(*) as newsgnum from userg where time > '2012-01' and type='1') sg
,
(select count(*) as newjlnum from userg where time > '2012-01' and type='2') jl
,
(select count(*) as newjsnum from userg where time > '2012-01' and type='3') js
,
(select count(*) as newjcnum from userg where time > '2012-01' and type='4') jc
,
(select count(*) as newkcnum from userg where time > '2012-01' and type='5') kc
,
(select count(*) as newzxnum from userg where time > '2012-01' and type='6') zx
,
(select count(*) as newzbnum from userg where time > '2012-01' and type='7') zb
,
(select count(*) as newclnum from userg where time > '2012-01' and type='8') cl
,
(select count(*) as newbxnum from userg where time > '2012-01' and type='9') bx这是我写的一个语句。
能得到这样的结果
我想要的是能穿个时间实时的查处这些数字来。。
谢谢!
FROM TABLE A GROUP BY to_char(A.TYPE),TRUNC(A.CINPUTTIME) ;
SELECT type,COUNT(*) FROM userg GROUP BY type ORDER BY type ASC;
select sum(decode(type,1,cc,0)) as sg,
select sum(decode(type,2,cc,0)) as jl,
select sum(decode(type,3,cc,0)) as js from
(select type, count(*) as cc from userg where time > '2012-01' group by type)
大致这样 比那个的效率应该要高一点,希望能帮到你