This is a follow up from a question I asked about a year ago Old thread The answers I got then have worked fine but now I discovered that I need to tweak the query to be able to get the latest end …
How to implement dimension table design when having different values for the same dimension according to specific criteria?
If I have a Dimension Date table like this: CREATE TABLE [Dimension].[Date]( [Date Key] [int] IDENTITY(1,1) NOT NULL, [Date] [date] NOT NULL, [Day] [tinyint] NOT NULL, [Day Suffix] […
Loop through JSON array in PLSQL 12.1
I have JSON array inside varchar DECLARE JsonArray varchar2(1000); arrayCars varchar2(1000); BEGIN JsonArray :={“Cars”: [{“name”:”Honda”, “color”:&…
Select Last Rows with Distinct Field
I have a table with the following schema: In this table only the id field is unique. I’m concerned with getting the rows containing the last X distinct itemid, ordered by date. For example, in the sample above, if I’d like to get the last 3 distinct itemid, I’d be getting the first 4 rows, s…
SQL show based on date condition
I have following query to start of with: I then get following table (only a snapshot for better desciption): I now have a problem: I only want to show the services where the service starting with ‘AAF21 OKN’ is first (by date). Patient ID: ‘Forløb10030’ is for example what i want. But …
Insert new records with several ids from another table
I have a table, which has 9 records with id = 1 – 9 (for example, there can be more than 20 ids). I have one varchar value = ‘premium’. I need to insert these values to another table, after this action I should have 9 records with id from the first table and ‘premium’ varchar in …
Firebird column unknown on SELECT AS
I have a table of calls and their durations: I want to select all numbers that called for over 500 seconds in total. My query uses SELECT AS to rename the SUM(…) field so I can reference it in the HAVING clause: When I run this query in Firebird SQL, I get the following error: Answer You can not use
Get pair-wise single row
I have some data in a MS SQL Server database. Sample data is: Sl ColumnA ColumnB 1 111 112 2 112 111 3 113 114 4 114 113 5 115 116 6 116 115 Now I need result like. ColumnA ColumnA 111 112 113 114 115 116 Notice here: In Sl 1 number Column A = Sl 2 Column B
Where am I going wrong in my cs50 pset 7 10.sql nested query?
I am currently trying to find the names of all people who have directed a movie that received a rating of at least 9.0 the scheme for these tables is MY SQL QUERY IS : This however fails the check50 test, and gives incorrect output. Can anyone help me with where I’m going wrong? Answer The spec says (em…
How use data in table as entity for key value in SQL?
I have a table as following: Is there any SELECT query to show table in following form? Thanks a lot. Answer You can try following code : UPDATE Since the table is containing more post_id’s, please check the following update.