Skip to content
Advertisement

Tag: pivot

SQL pivot query to get the result in a single row

I have a users table as I have another user_custom_fields table as and a third custom_fields table Here the problem is I need the result for each user in a single row with all the custom field_name as column header as I have heard about pivot queries but I don’t have much knowledge of SQL. Can anyone help me here

How query two different Sum from the same table for the same column but with different condition?

I would like to fetch the sum of field TOTAL for active users and sum of field TOTAL for inactive users. Expecting is the query that results activeTotal = 15 and InactiveTotal = 50 SELECT SUM(actUser.total) as activeTotal, SUM(inActUser.total) as inactiveTotal FROM user actUser JOIN user inActUser ON inActUser.id = inActUser.id WHERE (actUser.active = 1 AND actUser.userId = 1) OR

sql: long to wide format without using PIVOT

I have a table like the following: I want to convert the data to wide format like the following: the SQL I used does not have a pivot choice so I am wondering how to convert the long format to wide without using PIVOT. Answer If I understand your question correctly, you can do conditional aggregation: Maybe you want to

Advertisement