SELECT COUNT(*) AS cnt FROM ( (SELECT 'used' FROM b_names_1) UNION ALL
(SELECT 'used' FROM b_names_2)) AS t
WHERE 'used' = 1
这个码字很好..
但我想按时间间隔对结果进行排序,所以当我试图在底部添加这一行时,它不起作用:
AND registration_date_time >= STR_TO_DATE( '2013-01-28 00:00:00', '%Y-%m-%d %H:%i:%s' ) AND registration_date_time < STR_TO_DATE( '2013-02-02 00:00:00', '%Y-%m-%d %H:%i:%s' )
这段代码看起来像这样:
SELECT COUNT(*) AS cnt FROM ( (SELECT 'used' FROM b_names_1) UNION ALL
(SELECT 'used' FROM b_names_2)) AS t
WHERE 'used' = 1 AND registration_date_time >= STR_TO_DATE( '2013-01-28 00:00:00', '%Y-%m-%d %H:%i:%s' ) AND registration_date_time < STR_TO_DATE( '2013-02-02 00:00:00', '%Y-%m-%d %H:%i:%s' )
它给了我以下错误:#1054 - 'where 子句'中的未知列'registration_date_time'
知道如何正确地将日期代码实现到 SQL 中吗?