2012-12-03 70 views
0

我有獲取數據的從歧表錯誤在我的MySQL查詢

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 購買p JOIN PUR' 在行1

我無法想象它。請任何一個幫助我 在此先感謝

回答

0

您的查詢結果是OK。錯誤表明它在您的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.... 
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