表的结构是日期 号码 金额 状态
2009-11-23 9874 1000 0需要从表中取出每天总共有多少条记录,状态为0的有几条,总共的金额有多少,我写的MySql语句是这样的select distinct 日期,(select count(日期) from temptable tt where tt.日期=t.日期),
(select count(日期) from temptable tc where tc.日期=t.日期 and tc.状态=0),
(select sum(金额) from temptable ts where ts.日期=t.日期) from temptable t;
2009-11-23 9874 1000 0需要从表中取出每天总共有多少条记录,状态为0的有几条,总共的金额有多少,我写的MySql语句是这样的select distinct 日期,(select count(日期) from temptable tt where tt.日期=t.日期),
(select count(日期) from temptable tc where tc.日期=t.日期 and tc.状态=0),
(select sum(金额) from temptable ts where ts.日期=t.日期) from temptable t;
GROUP BY 日期
sum(if(状态=0,1,0)) as 状态为0的有几条,
sum(金额) as 总共的金额
from temptable
gruop by 日期
(select count(日期) from temptable where 日期=t.日期),
(select count(日期) from temptable where 日期=t.日期 and 状态=0),
(select sum(金额) from temptable where 日期=t.日期)
from temptable t;
如果状态=0, 结果为1,否则为0
再SUM求和
-> 3
mysql> SELECT IF(1<2,'yes','no');
-> 'yes'
mysql> SELECT IF(STRCMP('test','test1'),'no','yes');
-> 'no'