Samila Samila - 10 days ago 5
SQL Question

Group the Multiple row item into single row

Is it possible to get like this?

datetime | sysname | resource | metric | value
-------------------+---------+------------+-------------+-------
Nov 23,2016 2:00 | A | A-2 | Utilization | 0.30
Nov 23,2016 2:00 | A | A-2 | Throughput | 300
Nov 23,2016 2:00 | B | B-2 | Utilization | 10.8
Nov 23,2016 2:00 | B | B-2 | Throughput | 1080


Expected output:

datetime | sysname | resource | metric | value
------------------+---------+----------+--------+-------
Nov 23,2016 2:00 | A | A-2 | 0.3 | 300
Nov 23,2016 2:00 | B | B-2 | 10.8 | 1080

Answer
SELECT datetime, sysname, resource, a.value, b.value
FROM metrics a
     JOIN metrics b
        USING (datetime, sysname, resource)
WHERE a.metric = 'Utilization' AND b.metric = 'Throughput';
Comments