Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Categorize using spark sql

I have a table like following enter image description here

I want to summeraize it in to following table

enter image description here

How to do it using at least sql?

Edit class3 count should be 2. That's a typo

like image 251
Asiri Liyana Arachchi Avatar asked Oct 19 '22 01:10

Asiri Liyana Arachchi


1 Answers

This can be done in SQL as below

SELECT Org, SUM(CASE WHEN class='class1' THEN 1 ELSE O END) As Class1Count,
       SUM(CASE WHEN class='class2' THEN 1 ELSE O END) As Class2Count,
       SUM(CASE WHEN class='class3' THEN 1 ELSE O END) As Class3Count,
       SUM(CASE WHEN class='class4' THEN 1 ELSE O END) As Class4Count
FROM tableName
GROUP By Org
like image 199
Mudassir Hasan Avatar answered Oct 30 '22 03:10

Mudassir Hasan