Skip to content

Tag: sql

converting rows to columns using oracle sql

I’m trying to convert rows into columns using the following sample: LVL COL_VALUE TABLE_SRC 16 INT: ADDRESS_LINE_2:NULL INT 16 BASE: ADDRESS_LINE_2:X BASE 17 INT: ADDRESS_LINE_3:NULL INT 17 BASE: ADDRESS_LINE_3:X BASE The output should be: INT BASE INT: ADDRESS_LINE_2:NULL BASE: ADDRESS_LINE_2:X INT: AD…

How do I summarize sales data in SQL by month for last 24months?

I have big number of rows with sales for different products on various days. I want to retrieve the sum for each product and per month. For the last 24months. How do I write a WHERE function showing the last 24 months (based on latest date in table not actual date)? How is that summarized and shown by month i…

How can I use IF and CONCAT within SELECT

I have this Adjacency List Model table Table: Output: So I have the following query that duplicates a Site 1 e.g. and its children. In this case, the children are Paper with parent_id = 2 and ms1 with parent_id = 3 Output: As you can see Site 1 and its children got duplicated with a new unique id. However for

SQL How many of a counted row is in another counted row?

I’ve been stuck on how to write a particular query for the following question: How many employees are in how many businesses? My end result should look like this: EmployeeId Count BusinessId Count 1 23473423 2 56245764 3 834456 So there are 23473423 businesses that have 1 employee, 23473423 businesses t…