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: …
Tag: pivot
SQL Subquery with aggregate function – seeking alternative
My table (Table1) I did a sort of Pivot and it’s fine: http://sqlfiddle.com/#!18/45b9d/1/0 Now I need to calculate the difference between measures, to get something like this: But if I don’t use an aggregate, the result brings me null cells – http://sqlfiddle.com/#!18/45b9d/5/0 And if I do u…
Compare two values in a row
select event_slots.id as event_slot_id, u.first_name, u.id AS user_id, sum(case when next_round = 1 then 1 else 0 end) AS yes, sum(case when next_round = 2 then 1 else 0 end) AS no from event_slots …
MySQL-Statement. How do i skip rows in query where all rows equal null
I have created a query to construct a table with the following code: SELECT Date, SUM(CASE WHEN UniqueId = ‘NonComLong’ THEN Value ELSE NULL END) AS ‘NonComLong’, SUM(CASE WHEN UniqueId = ‘…
Single query to split out data of one column, into two columns, from the same table based on different criteria [SQL]
I have the following data in a table, this is a single column shown from a table that has multiple columns, but only data from this column needs to be pulled into two column output using a query: Required result: distinct values based on the first 13 characters of the data, split into two columns based on …
In SQL Server: Create Pivot Table with each Date as a own column
I have a table containing 4 different identifiers, a date and a numeric column like: from which I want to create a kind of pivot table like the following: This should be created for past 10 days or so, so it CRUCIAL I don’t have to set the dates manually. I tried something with PIVOT but that didn’…
SQL Stored Procedures, Combining rows with derived variables
I’ve been away for sometime and need help with, what is probably a simple solution but at this time I’m stuck. I have this select statement and need to combine rows with like elements for the same department but the group by would have a very large select list, is there another way like MERGE? Her…
How to select the most recent date for a specific condition in another column in Postgres?
I have a table with a structure like so. I’m trying to create a column with a query called most recent call which has the most recent call date for each id. Like this: I just want to have the most recent date for each id out of all the rows where the subject column equals call Answer You can
How to count multiple columns in SQL (Oracle) with criteria?
I’m working on SMS-Gateway that holds multiple charged SMS-services with different numbers, each SMS sent to the customer has 4 status as below (forwarded, delivered, expired,delivery failed) Now I have the below first_table for the charging-system with the below details (TABLE-A) and below (TABLE-B) wh…
T-SQL Pivot Behavior Question, Pivot not behaving as expected with CAS Numbers
I have a database of analytical laboratory data, one analyte per record (MS SQL Server Express 2014 (12.0.2000)). I have successfully (more or less) gotten results that I expect using a chemical’s …