首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

select 的过程中中文乱码有关问题求教

2012-08-13 
select 的过程中中文乱码问题求教select dates,concat(concat(replace(replace(TRUNCATE(part * 0.5 - 0.5

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 中文显示乱码

热点排行