1

我想问一下我有没有像下面这样的表

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

所以我在

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

我使用了错误的脚本吗?

请注意。

谢谢,

4

3 回答 3

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/

于 2013-02-26T04:19:35.097 回答
1

试试下面:

SELECT SUBSTR(calldate,1,13) as date_hour, dst, GROUP_CONCAT( lastapp )
FROM table
GROUP BY date_hour
于 2013-02-26T04:20:05.227 回答
0

这也将工作......

SELECT DATE_FORMAT(calldate,"%Y-%m-%d %h"), dst, GROUP_CONCAT( lastapp )
FROM cdr
GROUP BY hour( calldate ) ;
于 2013-02-26T04:25:51.000 回答