Reputation: 792
My query is...
SELECT
tbl1.FeeName,
SUM(tbl1.FeeAmount) AS TotAmt
FROM
tbl1
WHERE
tbl1.DateTaken BETWEEN '2017-06-02' AND '2017-06-06'
GROUP BY
tbl1.FeeId
The output is...
The table has other Fees that are not taken (transaction) between the above dates therefore not showing in the query
result.
I want to show those FeeNames and the value should be 0. Just like below (The yellow colored results).
What should I do ?
Upvotes: 2
Views: 223
Reputation: 12309
Try this : this will only perform sum operations of fees which are in given date range, for remaining fees this will put 0
SELECT
tbl1.FeeName,
SUM(CASE WHEN tbl1.DateTaken BETWEEN '2017-06-02' AND '2017-06-06'
THEN tbl1.FeeAmount
ELSE 0
END) AS TotAmt
FROM tbl1
GROUP BY tbl1.FeeId
Upvotes: 6