您應該使用對持有像1341241153
值日期列from_unixtime()
功能。
因爲這些值似乎以unix時間戳格式存儲。
例:
mysql> select
-> from_unixtime(1341241153) as 'my_datetime_1341241153',
-> date(from_unixtime(1341241153)) as 'my_date_1341241153',
-> curdate(),
-> curdate() > date(from_unixtime(1341241153)) 'is_today_later?',
-> curdate() = date(from_unixtime(1341241153)) 'is_today_equal?',
-> curdate() < date(from_unixtime(1341241153)) 'is_today_before?'
-> from
-> dual
-> \G
*************************** 1. row ***************************
my_datetime_1341241153: 2012-07-02 20:29:13
my_date_1341241153: 2012-07-02
curdate(): 2012-07-15
is_today_later?: 1
is_today_equal?: 0
is_today_before?: 0
1 row in set (0.00 sec)
您的查詢應該是:
SELECT a.name, COUNT(*) AS num FROM table2 b
INNER JOIN table1 a
ON (b.status_id=a.id and curdate() = date(from_unixtime(b.crm_date_time_column)))
GROUP BY status_id
絕對完美!非常感謝您的幫助!我已申請將此應用於大多數我需要做的除了我仍然遇到的問題之外還需要做的查詢!我爲此創建了另一個問題。如果你可以幫助解決這個問題,那也是很棒的。[鏈接](http://stackoverflow.com/問題/ 11495713 /返回結果的查詢爲基礎的今天日期在sql-mysql-part-2) – 5ummer5 2012-07-15 21:24:40