2021年5月7日星期五

return 0 when count(*) is null

I'm a beginner. Need ur help. I have two columns.

  1. A_VATNO and
  2. the number of A_VATNO counted.

When no A_VATNO counted nothing exported as a row.

I need to get a zero for those A_VATNO missing on my list.

Below example, I don't get anything for A_VATNO = '123456789' AND A_ALARMTYPE = '40' because no records on table ALARMS.

Example:

102030401  | 10   987654321  | 45  

Any solution to take as a final result this one?

102030401  | 10  987654321  | 45  123456789  | 0  

Thank you in advance!

 SELECT A_VATNO, COUNT(*)          FROM ALARMS      WHERE A_ALARMTYPE = '40' AND  A_VATNO IN    (     '102030401',  '987654321',  '123456789'     )     AND DATE(A_ALARM_DATE) >= '2015-01-01'       AND DATE(A_ALARM_DATE) <= '2015-12-31'             GROUP BY A_VATNO       ;  
https://stackoverflow.com/questions/67442302/return-0-when-count-is-null May 08, 2021 at 06:21AM

没有评论:

发表评论