我有這個查詢,我正在爲一次性報告工作。基本上我試圖做的是找到所有的記錄,上個月有一個帳戶ID有兩個以上的交易。我知道這可能是一件容易的事,我的想法只是空白。MySql計數查詢
SELECT streaming_transactions.account_id,
streaming_transactions_detail.transactions_description,
streaming_transactions_detail.transactions_detail_id,
streaming_transactions_detail.transactions_id,
streaming_transactions_detail.transactions_detail_amount,
streaming_transactions_detail.detail_type,
streaming_transactions_detail.products_id,
streaming_transactions_detail.products_levels_id,
streaming_transactions_detail.subscriptions_id,
streaming_transactions_detail.subscriptions_payment_options_id,
streaming_transactions_detail.modified
FROM streaming_transactions_detail
INNER JOIN streaming_transactions ON streaming_transactions_detail.transactions_id = streaming_transactions.transactions_id
WHERE streaming_transactions.charged = 1
AND streaming_transactions.timestamp_inserted > '2009-09-01 00:00:00'
AND streaming_transactions.account_id IN (
SELECT account_id
FROM streaming_transactions_detail
WHERE modified > '2009-09-01 00:00:00'
AND count(account_id) > 1)
AND streaming_transactions_detail.transactions_description LIKE '%Service Subscription%'
ORDER BY streaming_transactions.account_id DESC
哪些錯誤與您的查詢,是您得到不正確的結果或錯誤? – 2009-10-02 15:59:41
我收到一個錯誤。看起來你不能在WHERE子句中有count(),但是在HAVING子句中 – 2009-10-02 16:08:17