Skip to content

Tag: mysql

Summing the total of 4 alias

I have the following query: SELECT SUM(case when s1 = ‘fel’ then 1 else 0 end) as s1_count, SUM(case when s2 = ‘fel’ then 1 else 0 end) as s2_count, SUM(case when s3 = ‘fel’ then 1 else 0 …

Get column name of Table based on query

I have this SQL query Query And this is my table let’s say Tree_table So I want my output to be Is this possible using SQL query or even PHP will do Answer You need to unpivot the data. In MySQL, this is probably most easily done with union all: