Search Postgresql Archives

Re: SQL Query Help Please !

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/6/2010 3:06 AM, GrGsM wrote:

Hi all

I am using the following query for data to be displayed in crosstab :

   SELECT   closedate,status,
            SUM (CASE WHEN empcode = 'NT-028' THEN 1 ELSE 0 END) AS NT028,
            SUM (CASE WHEN empcode = 'NT-031' THEN 1 ELSE 0 END) AS NT031,
            SUM (CASE WHEN empcode = 'NT-050' THEN 1 ELSE 0 END) AS NT050,
            SUM (CASE WHEN empcode = 'NT-062' THEN 1 ELSE 0 END) AS NT062
         FROM   dbcleaning
    WHERE   status = 'Fixed'
            AND empcode IN
                     ('NT-028',
                      'NT-031',
                      'NT-050',
                      'NT-062')
GROUP BY   closedate, status

Now i need a column in the same result of the query which shows the
difference between the two columns .

SUM (CASE WHEN empcode = 'NT-028' THEN 1 ELSE 0 END) -
SUM (CASE WHEN empcode = 'NT-031' THEN 1 ELSE 0 END) as NT028_NT031

Or if you prefer, define an outer select with your select in the FROM clause; in the outer select, you can select each of the 4 columns plus any difference you like.

--
Guy Rouillier

--
Guy Rouillier

--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux