select dates,concat(concat(replace(replace(TRUNCATE(part * 0.5 - 0.5 * 1.0,1),'.5','点30分'),'.0','点'),' 至 '),
replace(replace(TRUNCATE(part * 0.5 * 1.0,1),'.5','点30分'),'.0','点')) as part_name,
sum(case role when 0 then 1 else 0 end) as call_in,
sum(case role when 0 then billsec else 0 end) as call_in_billsec,
sum(case role when 1 then 1 else 0 end) as call_out,
sum(case role when 1 then billsec else 0 end) as call_out_billsec
from(
SELECT substring(c.calldate,1,10) as dates,s.role,c.billsec,
ceil((HOUR(c.calldate) + MINUTE(c.calldate)/60 + SECOND(c.calldate)/3600 + 1/3600)/0.5) as part
from cdr as c,callsession as s
where c.userfield = s.callsessionid
) as a
group by dates,part查询结果如下
2012-03-05 14点 至 14点30分 2 10 2 13
2012-03-06 10点 至 10点30分 0 0 2 12
2012-03-06 12点30分 至 13点 1 6 2 10
2012-03-06 14点 至 14点30分 0 0 6 65
2012-03-06 15点 至 15点30分 1 6 20 43
2012-03-06 15点30分 至 16点 1 26 22 171
2012-03-06 16点 至 16点30分 6 158 9 190
2012-03-06 16点30分 至 17点 4 28 5 60
2012-03-06 17点 至 17点30分 1 4 11 59
2012-03-06 17点30分 至 18点 0 0 3 4
2012-03-14 11点 至 11点30分 0 0 13 0
但是当我在以上sql又套了一层select时select dates,part_name from(
select dates,concat(concat(replace(replace(TRUNCATE(part * 0.5 - 0.5 * 1.0,1),'.5','点30分'),'.0','点'),' 至 '),
replace(replace(TRUNCATE(part * 0.5 * 1.0,1),'.5','点30分'),'.0','点')) as part_name,
sum(case role when 0 then 1 else 0 end) as call_in,
sum(case role when 0 then billsec else 0 end) as call_in_billsec,
sum(case role when 1 then 1 else 0 end) as call_out,
sum(case role when 1 then billsec else 0 end) as call_out_billsec
from(
SELECT substring(c.calldate,1,10) as dates,s.role,c.billsec,
ceil((HOUR(c.calldate) + MINUTE(c.calldate)/60 + SECOND(c.calldate)/3600 + 1/3600)/0.5) as part
from cdr as c,callsession as s
where c.userfield = s.callsessionid
) as a
group by dates,part
) as b
order by dates desc查询结果就成
2012-04-23 14鐐?鑷?14鐐?0鍒
2012-04-23 16鐐?鑷?16鐐?0鍒
2012-04-23 13鐐?0鍒?鑷?14鐐
2012-03-31 10鐐?鑷?10鐐?0鍒
2012-03-31 9鐐?0鍒?鑷?10鐐
2012-03-23 15鐐?鑷?15鐐?0鍒
2012-03-23 14鐐?0鍒?鑷?15鐐
.......如何解决呢?
ps: sqlserver的强制转换类型我会,但是mysql的我实现不了,也求教