Tuesday, September 22, 2020

POSTGRESQL Tutorial - Select Count with Condition

 in Postgresql there is a way to select count with condition. in PostgreSQL 9.1 version cannot user Filter to get Select Count with Condition then should use CASE WHEN

first. I use this SQL

SELECT
COUNT(sjobstatus) FILTER (WHERE sjobstatus = 'CANCELLED') AS fclose
FROM rdr.xwkschrb 

working in my local PC but not working in liver server due to different Postgreql version. then i change to this SQL then working

SELECT
 COUNT(CASE WHEN sjobstatus = 'CANCELLED' THEN sjobstatus  END) AS close
FROM rdr.xwkschrb "

 

No comments:

Post a Comment

Item X-Ref di NB**

 SELECT AMASEI,AMAHIN,AMATOK,AMAETD FROM ZSTFI@L.AMAHINB WHERE AMASEI LIKE 'CF00156-S0A%'; hasil  AMASEI    AMAHIN    AMATOK    AMAE...