This type of questions already asked but that is not solve my problem.
I have table called scraping_data
+-----------------------------------------------------------+
| id | accountId | label | subLabel | status|
+-----------------------------------------------------------+
| 1 | 1 | Application | Nice | 1 |
| 2 | 1 | Application | poor | 1 |
| 3 | 1 | Application | Nice | 1 |
| 4 | 1 | Chennal | Quality | 1 |
| 5 | 1 | Application | Nice | 1 |
| 6 | 1 | Channel | poor | 1 |
+-----------------------------------------------------------+
Here I want to take counts by subLabel, for Example here label
Application comes 4 times with Nice times and poor 1 time. And same Channel come 2 times with Quality 1 time, poor 1 time.
My output will be like:
Application Nice count 3 and poor count 1
query:
SELECT * FROM scraping_data
2
Answers
Group by and Count.
You can do it using the conditional aggregation using
group by
andsum()
:Or using
count()
:To dynamically generate pivoted data you can use Prepared statements :
Demo here