I am writing a query that groups a table of users by (height, sex) and then gets the name of the user with the minimum weight for that combination of height and sex. If you wanna skip to the actual query, here is the SQLFiddle with a minimal representative example. If you don’t want to open that url, here is
Tag: group-by
Strange behavior of Oracle and group by
While analyzing performance of an SQL query in Oracle, I noticed a strange behavior. I noticed that Oracle’s plan behavior changes depending on value used in query. For example here is my table …
How do I select the max(timestamp) from a relational mysql table fast
We are developing a ticket system and for the dashboard we want to show the tickets with it’s latest status. We have two tables. The first one for the ticket itself and a second table for the …
SQL distinct values per group – how to “group by” and get a list of distinct values per group?
I need to do a bigquery/standard SQL statement (or a series of statements) that does “group by”, and returns a list of distinct values for each group (not count). for example for tables with headers …
Get value of column related to value of column in other rows
I’ve a current table like this and would like to obtain this desired table: As you can see, this desired table should have a fourth column which indicates me the proportional value of the price in …
Hive Most Popular in each group
I have three table BX-Books.csv ISBN, Book-Title, Book-Author, Year-Of-Publication, Publisher BX-Book-Ratings.csv User-ID ISBN Book-Rating BX-Users.csv User-ID Location Age I have to find most …
Grouping other fields by common email
I’d appreciate any assistance people could provide with this one. I’ve tried to follow a couple of other posts (GROUP BY to combine/concat a column), but when I do this, it combines everything. I …
MySQL Grouping using group_concat and then Group BY
I have a table like this: Basically, I want to group all names and give the count of such groupings like: Since there are 2 users with cooking and cleaning, 1 for washing and 4 for cooking. I am …
SQL Server : “invalid column name” error after GROUP BY on subquery
I am trying to perform the following query on a SQL Server database table with a GROUP BY on a column which results from a CASE statement done on a subquery: SELECT AVG(sales) as avg_sales, …
mysql – GROUP_CONCAT rows into a string
I have a following result set: req_id | p_id | ai_result | hash | sku 1 | 4 | Match | XAN | HOW 1 | 4 | Match | HXN | HOW 1 | 4 | Non Match | 123 | …