Hi Eric, I was actually trying to something similar with different data and tables a few weeks ago. With the help of a co-worker, we figured it out. It has to be a 2 step process. First you get a list of all the values you want as the column headings, in your case, the class name: select distinct class_name from backups.
Then using that list, you use the class_name in each of the CASE statement below: SELECT node_name, - COUNT ( CASE WHEN class_name = 'CLASS1' THEN class_name END ) AS CLASS1_COUNT, - COUNT ( CASE WHEN class_name = 'CLASS2' THEN class_name END ) AS CLASS2_COUNT - FROM backups - GROUP BY node_name I put it on multiple lines for readability, you can put it in a single line if you remove the "-". You can as many "COUNT(CASE..." as you have classes you want to report on. Thanks, Marc... Marc Lanteigne Spectrum Protect Specialist AVP / SRT IBM Systems, Spectrum Protect / Plus +1-506-460-9074 <- New phone number marclantei...@ca.ibm.com Office Hours: Monday to Friday, 7:00 to 15:30 Eastern IBM -----Original Message----- From: Loon, Eric van (ITOP NS) - KLM <eric-van.l...@klm.com> Sent: Friday, March 12, 2021 11:28 AM To: ADSM-L@VM.MARIST.EDU Subject: [EXTERNAL] [ADSM-L] SQL statement for multiple classes Hi everybody, I'm trying to figure out how to create a SQL query to retrieve the amount of files, per management class, per node in just one query. The ideal output would be: Nodename Class1 Class2 Class3 Mynode1 1234 475859 3645895 Mynode2 12345 274368746 8948382348 If you select a count(*) from archives where class_name='CLASS1' you will only get the amount stored for Class1, so I will have to be able to combine multiple select count(*) from archives where statements in one single query. Thank you very much for your help! Kind regards, Eric van Loon Air France/KLM Storage & Backup ******************************************************** For information, services and offers, please visit our web site: https://urldefense.proofpoint.com/v2/url?u=http-3A__www.klm.com&d=DwIFAg&c=jf_iaSHvJObTbx-siA1ZOg&r=hMBqtRSV0jXgOdXEmlNk_-O9LHkPCGSh9PJBRSlL8Q4&m=VWhWIjh8f1o6bOJU--Dyv18M24wkeOsRi9NVBNYTF8M&s=DIet3oaetjF82rRyOIjA5Ibn2C3SPlm_dhHS7zLTA1o&e= . This e-mail and any attachment may contain confidential and privileged material intended for the addressee only. If you are not the addressee, you are notified that no part of the e-mail or any attachment may be disclosed, copied or distributed, and that any other action related to this e-mail or attachment is strictly prohibited, and may be unlawful. If you have received this e-mail by error, please notify the sender immediately by return e-mail, and delete this message. Koninklijke Luchtvaart Maatschappij NV (KLM), its subsidiaries and/or its employees shall not be liable for the incorrect or incomplete transmission of this e-mail or any attachments, nor responsible for any delay in receipt. Koninklijke Luchtvaart Maatschappij N.V. (also known as KLM Royal Dutch Airlines) is registered in Amstelveen, The Netherlands, with registered number 33014286 ********************************************************