我想问一下我是否有如下表
Date & Hour Phone Status
2012-03-06 16:33:12 0292561234 Congestion
2012-03-06 16:33:12 0292561234 Congestion
2012-03-06 16:34:45 0292561234 Congestion
2012-03-06 16:46:50 0292561234 Congestion
2012-03-06 17:17:01 0292561234 Dial
2012-03-07 12:01:39 500 Queue
2012-03-07 12:02:10 500 Queue
2012-03-07 12:03:06 500 Queue
我需要像
一样加入他们Date & Hour Phone Status
2012-03-06 16 0292561234 Congestion,Congestion,Congestion
2012-03-06 17 0292561234 Dial
2012-03-07 12 500 Queue,Queue,Queue
所以我在
中使用了CONCAT条件SELECT calldate, dst, GROUP_CONCAT( lastapp )
FROM cdr
GROUP BY hour( calldate ) ;
但它显示为
Date & Hour Phone Status
2012-03-06 16:33:12 0292561234 Congestion,Congestion,Congestion,Dial
2012-03-06 17:17:01 0292561234 Dial
2012-03-07 12:01:39 500 Queue,Queue,Queue
我使用的是错误的剧本吗?
请注意。
谢谢,
答案 0 :(得分:1)
尝试此查询
SELECT DATE(calldate), dst, GROUP_CONCAT(lastapp)
FROM tbl
GROUP BY dst, DATE(calldate);
参考http://www.mysqlperformanceblog.com/2006/09/04/group_concat-useful-group-by-extension/
答案 1 :(得分:1)
尝试以下:
SELECT SUBSTR(calldate,1,13) as date_hour, dst, GROUP_CONCAT( lastapp )
FROM table
GROUP BY date_hour
答案 2 :(得分:0)
这也有效......
SELECT DATE_FORMAT(calldate,"%Y-%m-%d %h"), dst, GROUP_CONCAT( lastapp )
FROM cdr
GROUP BY hour( calldate ) ;