我进行查询,我认为它的语法正确:
SELECT a1.androidPackage, a1.country, a1.revenueRate as old_CPI,
a2.revenueRate as new_CPI
FROM ad_appnext a1
WHERE DATE(date_created) = CURDATE() AND country = 'UK'
INNER JOIN
(SELECT *
FROM ad_appnext
WHERE DATE(date_created) = '2014-04-02' AND country = 'UK') a2
ON a1.androidPackage = a2.androidPackage
WHERE a1.revenueRate != a2.revenueRate;
但是当我运行时显示问题:
错误1064(42000):您的SQL语法有错误;检查 手册,对应右边的MySQL服务器版本 在&JONER ININ JOIN附近使用的语法(SELECT * FROM ad_appnext WHERE DATE(date_created)=' 2014-04-02' AN'在第1行
请帮我解决这个问题。
答案 0 :(得分:4)
您有两个WHERE子句。你应该只有一个,它应该在FROM子句之后。
SELECT a1.androidPackage, a1.country, a1.revenueRate as old_CPI, a2.revenueRate as new_CPI FROM ad_appnext a1
INNER JOIN (SELECT * FROM ad_appnext WHERE DATE(date_created) = '2014-04-02' AND country = 'UK') a2 ON a1.androidPackage = a2.androidPackage
WHERE a1.revenueRate != a2.revenueRate"
AND DATE(date_created) = CURDATE() AND country = 'UK'
答案 1 :(得分:1)
您有两个WHERE子句
试试这个
SELECT a1.androidPackage, a1.country, a1.revenueRate as old_CPI,
a2.revenueRate as new_CPI
FROM ad_appnext a1
INNER JOIN
(SELECT *
FROM ad_appnext
WHERE DATE(date_created) = '2014-04-02' AND country = 'UK') a2
ON a1.androidPackage = a2.androidPackage
WHERE DATE(date_created = CURDATE() AND country = 'UK'
and a1.revenueRate != a2.revenueRate;