我有两张表,一张用于跟踪聊天统计信息,一张用于跟踪邮件统计信息。
我当前的查询如下所示:
SELECT COUNT(id) as chat_amount, DATE_FORMAT(timestamp, '%b %e') as period FROM tblChats WHERE timestamp BETWEEN '{$start}' AND '{$end}' AND UserID = 0 GROUP BY DAY(timestamp) DESC, MONTH(timestamp) DESC, YEAR(timestamp) DESC
SELECT COUNT(id) as mail_amount, DATE_FORMAT(timestamp, '%b %e') as period FROM tblMails WHERE timestamp BETWEEN '{$start}' AND '{$end}' AND UserID = 0 GROUP BY DAY(timestamp) DESC, MONTH(timestamp) DESC, YEAR(timestamp) DESC
我想将这两个查询合并为一个,以便返回的数据如下所示:
Array (
[0] => Array (
[period] => 2012-11-09
[chat_amount] => 1500
[mail_amount] => 100
)
[1] => Array (
[period] => 2012-11-08
[chat_amount] => 500
[mail_amount] => 350
)
[2] => Array (
[period] => 2012-11-07
[chat_amount] => 2000
[mail_amount] => 1300
)
[3] => Array (
[period] => 2012-11-06
[chat_amount] => 1000
[mail_amount] => 970
)
)
我怎样才能实现这样的目标?先感谢您。