Skip to content

Tag: sql

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:

Finding employees who are not managers

I have a table where we have staff_id and manager_id. Attached screenshot. I found managers by using this query: select e.first_name as employee , m.first_name as manager from sales.staffs E inner …