New answers tagged

0 votes

Conditional selection in a GROUP BY clause

Using FIRST_VALUE the query would be a little simpler. Using the following data example CREATE TABLE cities ( country VARCHAR(20), city VARCHAR(20), population INT ); INSERT INTO cities ...
Ergest Basha's user avatar
  • 3,685
0 votes

Conditional selection in a GROUP BY clause

You need to join the country and population as follows SELECT A.country,A.city,A.pop population FROM (SELECT country,city,population pop FROM cities) A INNER JOIN (SELECT country,MAX(population) pop ...
RolandoMySQLDBA's user avatar
1 vote
Accepted

Why use $group / group_by instead of multiple requests?

why perform a query involving $group which in principle processes each document sequentially This is not necessarily true. The database engine is designed to be optimized for such type of operations, ...
J.D.'s user avatar
  • 34.1k
1 vote

Adding subtotals using GROUPING SETS

This is a translation of your description into SQL: ... GROUP BY GROUPING SETS ((store, department, gender), (store))
Laurenz Albe's user avatar
  • 45.8k
1 vote

Select first row of a particular group with one attribute selected as 0 while all other rows should be selected as is

I am currently doing the above by breaking/splitting my queries. Is it possible to do this in a single query? Sure, you can use a window function in a subquery to order the rows within a grouping (...
J.D.'s user avatar
  • 34.1k

Top 50 recent answers are included