0

我有一个从不同表中获取数据的查询

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 服务器版本相对应的手册,以在第 1 行的 'SELECT p.USER_NAME,count(*) as total, pi.UpdatedDate FROM purchase p JOIN pur' 附近使用正确的语法

我想不通。请任何人帮助我提前谢谢

4

2 回答 2

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
于 2012-12-03T06:18:44.820 回答
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....
于 2012-12-03T06:08:36.897 回答