Skip to content
Advertisement

Tag: common-table-expression

WITH queries with INSERT in MySQL

I’m trying to do something that I’m almost positive works in Postgresql: In other words, I want to grab the “something” row to be used for a bunch of new rows in “somwhere”. Each new entry should have a reference (like foreign key value) back to the same “something” row in the cte, mostly just to avoid a mess. However,

Trying to delete duplicate rows in SQL Server where the difference is the date or batch number

I have this query: Which is returning the following results ID_NUMBER INCEPTION_DATE OCCURRENCE TRANSACTION_DATE FILE_LOAD_DATE BATCH_NUM 112897732 2008-09-15 4 2008-07-03 2008-07-07 17:57:19 06341 112897732 2008-09-15 4 2008-07-13 2008-07-18 03:35:55 06753 828194721 2008-11-11 1 2008-09-06 2008-09-17 02:50:44 97334 828194721 2008-11-11 1 2008-09-23 2008-09-24 02:55:27 98331 456457422 2008-09-28 1 2008-12-03 2008-07-13 08:08:39 00734 456457422 2008-09-28 1 2008-12-03 2008-07-18 13:35:55 00991 999272910 2008-05-07

How to retain the first record while using Window function LAG()?

I have a data which looks like – Actual Table – VIN Mode Status Start End ABC123456789 Mode 1 Waiting for Auth 01/01/2010 00:00:00 05/05/2014 14:54:54 ABC123456789 Mode 1 Waiting for URL 05/05/2014 14:54:54 05/13/2014 19:09:51 ABC123456789 Mode 1 Waiting for User 05/13/2014 19:09:51 11/13/2014 22:26:32 ABC123456789 Mode 1 Authorized 11/13/2014 22:26:32 11/13/2014 22:31:00 ABC123456789 Mode 1 Authorized 11/13/2014 22:31:00

Cycle detected while executing recursive query

I am using CTE recursive query to get below output but don’t know why it is throwing “cycle detected while executing recursive WITH query”. Can anyone please tell me where is wrong with my query? my query: SELECT order_id, product_id, quantity FROM cte; table/data script: Answer In the recursive member you are currently only joining on a.product_id = b.product_id, rather

cte FULL OUTER JOIN MYSQL

I have this table(called trial): ‘year1’ refers to values in Column ‘val1’, ‘year2’ to values in Column ‘val2’. I want to get totals of all values grouped by year. So I would like to see a result like: I set up a common table expression(cte) using a self join to do this as follows: (The first four output columns are

Advertisement