SELECT 
    sum(qty) as accept,
    (SELECT sum(qty) 
     FROM pile 
     WHERE pf=false) as reject 
FROM pile 
WHERE pf=true;
That's the SQL I use currently, but I'm guessing its not best practice?
The other alternative I used before was  SELECT sum(qty) FROM pile GROUP BY pf but I need them as columns and not as rows.
Are there any other solutions?
SELECT pileTrue.sumTrue as accept, pileFalse.sumFalse as reject
FROM
(SELECT sum(qty) sumFalse FROM pile WHERE pf=false) as pileFalse,
(SELECT sum(qty) sumTrue  FROM pile WHERE pf=true ) as pileTrue
                        Single pass through the table.
SELECT 
    sum(CASE WHEN pf = TRUE THEN qty ELSE 0 END) as accept,
    sum(CASE WHEN pf = FALSE THEN qty ELSE 0 END) as reject
FROM pile;
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With