I want to check whether my customer owns an iPhone, iPad, or Macbook. I am not looking for how many iPhone or iPad or Macbook one customer has, I just want to identify if they own any of them, or if they own any two, or if they own all three. I am thinking of using the CASE WHEN function
Tag: pivot
Aggregating data with SQL if other values in rows meet certain criteria
I’m pretty new to SQL and am trying to figure out if there’s a way to aggregate the date into new column. For instance, below is a sample set of date. I want to take all the type ‘2’ and create new …
Getting the result of sum / count with two different conditions
I’ve been trying to extract to average times (based on some criteria). I need to get two results. These two results are based on how many minutes between two times, divided by the quantity of …
Creating a Pivot Table in SQL
I could use some help with creating a PIVOT table. The table that I’m looking to pivot from is: Where I want to change it into the Format of Which has the tracking number as the Row Identifier, the added columns are the Unique Values in the ‘Surcharge Reason’ column, and the values of the da…
Improve pivot view performance
I have a key-value structure for storing dynamic entities (standard EAV). I made a view for this Entity with the Pivot command. I tried to set the index for this view, but it is not possible due to the use of pivot. Is there a way to drag my data into SQL at the time of insert, Update? Because performance
String Aggregtion to create pivot columns in Big Query
I am trying to implement this exact solution linked below, but it seems GROUP_CONCAT_UNQUOTED is no longer a valid BQ function. Is there a solution to this that works in 2020? p.s. I would have just …
I am getting a “subquery returning multiple rows” error. I want to return multiple rows however
I want to have a subquery which returns multiple rows in MySQL. I used the IN function as well. However i am getting a “subquery returning multiple rows” error. I have attached an image of the tables used and the desired output Here is my SQL code: Answer You seem to want conditional aggregation:
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. An…
Merging query from same table into different columns
I’m having an issue querying a table for some information. Basically the way data was stored in the table, for every customer, its information was stored vertically and so on for others. In my case I want to display in separate columns for example only the ‘Company’ and ‘StreetAddress&…
Pivot data row to header using SQL in Postgresql
I get this result using SQL request: NBR_TYPE Count ———————– 0021 20 0022 19 0023 13 But i want result like this : 0021 …