My SQL Server problem is as follows: let’s say we have clients and we wish to rate them based on 4 categories (Score_1…Score_4) on a scale of 0 to 2. I have a table presented below: What I want my code to do is count the number of 0, 1, and 2 values each of my clients recieved. The result
Tag: unpivot
MySQL select all column names where condition is met for specific row
I have a table which links users to groups which is set up as below: I would like to know if there is a method to select all groupIDs (column names) where a certain condition is met. E.g. if I want to find all groups where user 2 has a level greater than 0 it would return (1,2,4) It is
SQL Server 2008 R2 split one row of results into two rows
In simple terms the table (t1) looks like this: I’d like to get results from the table that looks like this: Thanks Answer You may try simple query, using operator Union:
Evaluate Multiple conditions for same row
I have to compare 2 different sources and identify all the mismatches for all IDs Source_excel table Source_dw table Expected result I have tried the below query but it is giving only one mismatch. Actual output I understand that case expression will only check the first satisfying condition. Is there any other way I can check all the condition? Answer
Stored procedure to unpivot
I have a table with these columns: Where fields from 01 to 50 are dates. I need to have a table like this: Where title code should be the column name from 01 to 50, data should be the value of that column in mytable I did this stored procedure by looking in older questions: but I’m getting a syntax
Transform Columns to Rows dynamically using T-SQL
I have the following table where I need to transform Columns to Rows tbl_Survey: I need to have the following result: To have this result I used the following code: But, my Quest_1, Quest_2, Quest_3 values could potentially be changed / or even added a new once… Are there ways to code them, so it can be used for any
Convert rows to columns using PIVOT
I have a table named AmountList in SQL Server : where Primary key is ” UniqueCol1, UniqueCol2, AmountID ” and on the basis of AmountID I want to Pivot the results as: I am facing the challenge using Pivot because only Aggregate functions can be used but I need actual values of the fields. UPDATE: Added my attempt for the
Sql Syntax to tag rows in a table where this specific criteria appears at least once or more
I am using SQL Server 2014 and I have a table (t1) which contains a list of 6 numbers in more than 25,000 rows. Extract of t1 is given below: Id F1 F2 F3 F4 F5 F6 1 5 11 15 …
Replace row with Column Data in Sql Server
I have a table with some data and I was trying to Replace the Column with Row. The above Query gives me the result in one single row data. But I want the Result in below format I have tried the Pivot Operator using Derived Column but got confused during implementation. Please help to get the correct query. Answer Assuming
Comparing Substring Against Multiple Columns
I have a table which has 20 similar text attribute columns, text1..text20. These columns are of type CLOB. I am looking to find rows where one of these text attribute columns contain a specific phrase, such as ‘%unemployed%’. I need to know 2 things, which rows match, and which column was matched on. I thought I could use ANY as