SQL : Keep ONE row with max value on a column depending on value of another column

It’s well documented on StackOverflow how to find the whole data for the row with some max value in a column per some group identifier (SQL select only rows with max value on a column). But that given …

How can I select the max for a maths operation and also other elements without the max displaying all results

I am trying to find the maximum value of something, while also selecting other attributes at the same time. When i do the max statement on its own, it works as intended, but when I select another …

Limited By Value Postgresql query

I have a couple of rows where values in one column are repeating and I need to get a couple of rows where every value is limited by const. For example, i have this rows (1, ‘a’) (2, ‘b’) (3, ‘a’) (4,’…

How to fix my postgres function syntax to fit a user parameter

I’m trying to make a postgreql function, I’m a little confused on which syntax format to use when I’m passing a select statement that takes in a parameter (this parameter can be a string or a list of …

Group and subquery issue

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’, ‘…

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 …

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), (…

Oracle SQL: how to show only one max per group

Hi everyone first thanks for your time. I have this data Data: And I have to obtain the max values of everygroup, if there is one group that has two same max values like A 40 23/56/1982 A 40 31/4/…