我有一个从差异表中获取数据的查询
SELECT p.USER_NAME,count(*) as total, pi.UpdatedDate FROM purchase p JOIN purchasedissues pi on pi.PurchaseId=p.PURCHASE_ID WHERE pi.UpdatedDate>DATE_SUB(NOW(), INTERVAL 1 HOUR) AND p.PURCHASE_DATE=CURDATE() AND p.USER_NAME NOT IN (SELECT username from tbl_test_user) GROUP BY p.USER_NAME having count(*)>2
但我收到了错误
#1064
- 您的SQL语法出错;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 在'SELECT p.USER_NAME附近,count(*)为总,pi.UpdatedDate FROM 在第1行购买p JOIN pur'
我无法理解。请任何人帮助我 提前谢谢
答案 0 :(得分:0)
您的查询没问题。该错误表明它位于SELECT p.USER_NAME,...
附近。当您执行多个查询而不终止它时,通常会发生这种情况。前,
SELECT * FROM tableName
SELECT p.USER_NAME,count(*) as total, pi.UpdatedDate FROM purchase....
所以要纠正它,只需添加一个分隔符(通常如果不改变,它是分号)来结束你的第一个查询
SELECT * FROM tableName; -- <== this one
SELECT p.USER_NAME,count(*) as total, pi.UpdatedDate FROM purchase....
答案 1 :(得分:0)
试试这个查询!不知道它是否有效,因为我没有在我的机器中设置环境,但它可能会给你一个测试它的本质:)
SELECT p.USER_NAME,count(*) as total FROM purchase p JOIN purchasedissues pi on pi.PurchaseId=p.PURCHASE_ID WHERE pi.UpdatedDate>DATE_SUB(NOW(), INTERVAL 1 HOUR) AND p.PURCHASE_DATE=CURDATE() AND p.USER_NAME NOT IN (SELECT username from tbl_test_user) GROUP BY p.USER_NAME having total > 2