0
我想查詢我的數據庫,只顯示收到至少60%的訂購電話的記錄。查詢mysql有兩個條件
這裏是我的表中的一個精簡版:
dealID | Ordered | Received | precreditEL | cancelled | precredit
1 | 5 | 4 | | |
2 | 2 | 2 | | |
3 | 10 | 2 | | |
4 | 8 | 8 | Non-applicable | |
5 | 6 | 5 | Non-applicable | Cancelled | Ready
這裏是我當前的查詢
select deals.dealID,customer_info.accName,account_info.accessid,account_info.access_password,customer_info.contactNumber,deals.est_bill,deals.precreditAssigned,deals.precreditEL,deals.precredit
from customer_info join deals
left join account_info on account_info.custID = customer_info.custID
left join phone_details on phone_details.dealID = deals.dealID
where customer_info.custID = deals.custID
and deals.precreditEL <> 'Non-applicable'
and deals.precredit <> 'Complete'
and deals.cancelled IS NULL
GROUP BY deals.dealID
having ((100 - (((sum(phone_details.ordered) - sum(phone_details.received))/sum(phone_details.ordered)) * 100)) >= 60)
這完美的作品。只要precreditEL
不是不適用,並且其未標記爲已取消,該查詢將給我已收到已訂購訂單的60%的記錄。所以我的結果將是dealID 1 and 2
。
但現在我需要添加另一個條件,繞過這種情況。如果precredit
被標記爲Ready
,則無論上述條件如何,結果都將顯示記錄。所以我的結果將顯示dealID 1, 2 and 5
任何幫助,將不勝感激。非常感謝你。