select 的过程中中文乱码问题求教
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-0514点 至 14点30分210213
2012-03-0610点 至 10点30分00212
2012-03-0612点30分 至 13点16210
2012-03-0614点 至 14点30分00665
2012-03-0615点 至 15点30分162043
2012-03-0615点30分 至 16点12622171
2012-03-0616点 至 16点30分61589190
2012-03-0616点30分 至 17点428560
2012-03-0617点 至 17点30分141159
2012-03-0617点30分 至 18点0034
2012-03-1411点 至 11点30分00130
但是当我在以上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-2314??14?0
2012-04-2316??16?0
2012-04-2313?0??14
2012-03-3110??10?0
2012-03-319?0??10
2012-03-2315??15?0
2012-03-2314?0??15
.......
如何解决呢?
ps: sqlserver的强制转换类型我会,但是mysql的我实现不了,也求教
[解决办法]
set names 'gbk'; 先试一下。
http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
MySQL 中文显示乱码