I have data that looks like this: And I would like it to look like this: I think a dynamic conditional aggregation is required. Any help would be appreciated. Answer Here is a sample implementation of dynamic conditional aggregation: this is the result: Now you can add a value (for example id = 4 and value = ‘e’) replacing the
Tag: tsql
Return value from another table that matches values from the first table
I have a simple problem. I have tables A and B, both contain 3 common columns (name, id, date), and besides those 3, both tables have completely different set of columns. Now, I need to relate data from Table B to table A for visualization purposes. Since I am not that good with SQL, I thought I could ask if
How can I join result from two queries
So sorry but I am new to SQL querying and could use a little help. I will like to join results from 2 tables and I can’t seem to get it return results I need. Query 1 Query 2 I tried using union all but I get an error must have equal number of expressions in their target lists. Any
Replace function in SQL Server
I have a string of data I am trying to use the replace function to replace double commas with NULL values Solution But I keep ending up with (The ,,, needs to become ,NULL,NULL, but only becomes ,NULL,,) Here is my sample code I’m using Answer If you do the same replacement twice, any number of sequential commas will get
MS SQL Find a Value in entire column and return true if found
New to SQL trying to find how to do the following : I have a ProductID# ABC123 (Product) I need to check the “workflow” (Workflow) column and see if the Product ID was ever “extended” – there are various workflow steps – Need to check the entire workflow column, if a ProductID was ever “extended” I need to mark “yes”
Correspondence between two tables
I have table the table code_Commune contains gps for the city in general code_Commune: Now I need to do correspondence with the table lead to add code_commune and Nom_Commune: Table lead Is there any way to do correspondence between the two tables? Answer You can find the closest city using some sort of distance measure. First, fix your first table:
Selecting 7th Person (row) and get 7 as result
I want to select the 7th person (Pierre Gasly (for example)) Score list Season F1, so I can return number 7 in my C# application. SELECT CONCAT(strVoorNaam, strTussenVoegsel, ‘ ‘, strAchterNaam) AS …
SQL SERVER JOIN ID rows from one SELECT query to second SELECT query
Our fleet drivers accumulate hours in each type of rig that we operate. This first query returns a list of driver IDs for a given route. Result: I need to feed these IDs into this second query, which returns the number of accumulated hours for a given Driver ID. I’m trying to achieve: EDIT: For clarification, if it helps, both
How formulate a SQL query that needs to mention four different tables?
I want to get the Company name and all the products they purchased in a single SQL query. The database used is the Northwind sample database. The relations between these columns and dbs’ tables look …
Group by to include case statement inside SQL statement
I have a table which stores purchase info from sellers and table contains rating to every purchase out of 5 stars. I want to have output Group By sellers and Each sellers good(Above 3) and bad(Below 4)…