I have a Oracle database table like so, which records an item being scanned at a scanning point.
ItemsScan
ItemScanId
ItemScanPoint
ItemType
ScanTime
I want to return the ItemScanPoint along with the number of times a specific ItemType was scanned at that ItemScanPoint.
Something along the lines of..
SELECT ItemScanPoint,
       (SELECT COUNT(*) WHERE ItemType = 1),
       (SELECT COUNT(*) WHERE ItemType = 2)
FROM   ItemsScan
How do I do this in oracle?
What is the most efficient way?
SELECT   ItemScanPoint,
         SUM(CASE ItemType WHEN 1 THEN 1 ELSE 0 END) ,
         SUM(CASE ItemType WHEN 2 THEN 1 ELSE 0 END)   
FROM     ItemsScan 
GROUP BY ItemScanPoint
                        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