[英]MySQL query to show results
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. 该表具有上述日期之间未收取的其他费用(交易),因此未在
query
结果中显示。
I want to show those FeeNames and the value should be 0 . 我想显示那些FeeNames,其值应为0 。 Just like below (The yellow colored results).
如下所示(黄色结果)。
What should I do ? 我该怎么办 ?
Try this : this will only perform sum operations of fees which are in given date range, for remaining fees this will put 0 试试这个:这只会执行给定日期范围内费用的总和运算,对于剩余费用,这将为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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.