0
我的查詢結果如下 訪問數據庫總字段不計算空記錄?
查詢:
SELECT reservations.customerid,
(SELECT SUM(balances.balance) FROM balances
WHERE balances.customer_id = reservations.customerid)
AS Preveious_balance ,
(SELECT SUM(services.Amount_due)
FROM services
WHERE services.customer_id = reservations.customerid
AND services.status=0) AS Service_due ,
(SELECT SUM(foods.Amount_due)
FROM foods WHERE foods.customer_id = reservations.customerid
AND foods.status=0) AS Food_due,
((due_nights.Due_nights - reservations.billed_nights) * rooms.rate)
as Accomendation,
(Preveious_balance + Service_due + Food_due + Accomendation)
AS Total_due
FROM reservations, due_nights, rooms
WHERE reservations.customerid = due_nights.customerid
AND reservations.roomno = rooms.roomno
Total_due是空的,如果一些列值變空的,所以如何解決這一問題?
try nz(SUM(balances.balance),0)AND CHECK – Sachu
@Sachu in Sir Sir – Saedawke