我試圖寫一個返回下面列的查詢問題:我的WHERE子句(SQL)
owner_id,
number_of_concluded_bookings,
number_of_declined_bookings,
number_of_inquiries
然而,問題是,我的WHERE子句攪亂查詢,因爲我查詢同一張桌子。這裏是代碼:
SELECT owner_id,
Count(*) AS number_of_cancelled_bookings
FROM bookings
WHERE state IN ('cancelled')
GROUP BY owner_id
ORDER BY 1;
很容易單獨檢索列,但我希望所有這些。假設我想要number_of_concluded_bookings
以及那將意味着我將不得不改變WHERE子句...
幫助非常感謝!
你能提供從預訂表中的一些樣本數據? – supergrady
您需要一個條件集合:'COUNT(CASE WHEN IN IN'('cancel')THEN 1 END''或'SUM(CASE WHEN IN INE''''''')然後在每個條件下重複此操作 – dnoeth
這不夠好?https://gyazo.com/9d65a59eb26be135e6bf44b85ead15b7 – DBE7