This is my sample data CREATE TABLE customer1 ( rating int(9), genre varchar(100), title varchar(100) ); INSERT INTO customer1 (rating, genre, title) VALUES (2, ‘A’, ‘abc’), (4, ‘A’, ‘…
Tag: greatest-n-per-group
Querying a cte – The multi-part identifier could not be bound. How do I fix this so I can query the table? New to SQL accounting background
I am trying to extract a dataset which joins 3 tables Employee E AbsenceTypes AT AbsenceBalance AB In the data set I need the most recent record from AB.BalanceTime for each AB.EmployeeUID by AB….
List values with MaxDate
Im trying to create ie query to show itens with MAX DATE, but I don´t know how ! Follow the script and result: I need to show only tasks with the last date of each one. Can you help me ? Answer You seem to be using Postgres (as suggested by the use of casting operator ::). If so –
ORA-00904: “GRADE_RANK”: invalid identifier
This query runs without grade_rank > 1 but I want only the results where grade_rank is > 1. I have tried using ROW_NUMBER() OVER() as grade_rank but it didn’t work. SELECT student_id, …
Get rows with a condition
Each customer can have one or multiple accounts (account_id) How can I get max closed_date for the customers who closed all their accounts and the rest of the active customers?* *active customers are …
How can I pull out the second highest product usage from a SQL Server table?
We have a product usage table for software. It has 4 fields, [product name], [usage month], [users] and [Country]. We must report the data by Country and Product Name for licensing purposes. Our rule …
Define two or more conditions into a stored procedure with inner join?
First, I needed to filter the data from the tables TbTaxCompanies and tbCompany, through the variable @company_id… and works! And second I need to filter again the set of logs from the company selected previously with @company_id, but now to obtain only the latest updated taxes (only one row)… and this DOES NOT WORK! I really appreciate any help. Answer
Find Nth value and average value corresponding to each group in SQL
I have a table with name and grades for some users CREATE TABLE grades (name varchar(100), grade integer); insert into grades values (‘Bob’, 12), (‘Bob’, 13), (‘Bob’, 23), (‘Bob’, 17), (‘James’, 15), (…
Select max value for each company in list, display longest value per company per day
I’ve looked at some of the other questions similar to this, but nothing I’ve found can quite get me there. I have a table with multiple columns, but 3 of the columns are Company, Date, and WaitTime. I want to select the longest WaitTime for each company and for each day. I’d like to display the results for the entire
Select first and nth order for each client
I’m trying to display first and fifth order_id for each user. Table looks like this: I wrote something like this: But I want to see clients who made their first orders but don’t have fifths. There should be NULL, but I can’t understand how to make it. :c Answer Put the where t2.rn = 5 condition into the left join: