Skip to content
Advertisement

SQL query subtable in columns from main query

I have 2 tables with a main table with a unique UUID as index and a sub-table containing the languages of 1 row of the main table. E.g. table_1 uuid code 111-etc 123 222-etc 321 table_1_lang uuid lang_code title 111-etc en english 123 111-etc de deutch 123 222-etc en english 321 222-etc de deutch 321 I want to create a

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: ADDRESS_LINE_3:NULL BASE: ADDRESS_LINE_3:X The COL_VALUE with the same LVL should be in 1 row I tried using PIVOT but

How to fix NEXTVAL returning null in insert query but returns correct value when executed alone in PostgreSQL?

When I execute the following insert query: I get the following output: The third column which is supposed to be filled by the NEXTVAL function result is being sent null, which is violating a certain non-nullity constraint. However when I execute NEXTVAL independently like this: The function returns a correct value as shown below in the screenshot: Answer Your insert

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 instead

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

Function to check if a date is a Christmas day or New Years day

I am creating a function in SQL Server to validate if given date is a Christmas day or new year’s day. Please kindly advise if following code is OK: Above is the simplest way I can think of regardless or timezone and date format Answer I would create a table-valued function like this, rather than what I suspect is a

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 that have 2 employees, etc. I have a table with

Advertisement