MySQL - group By several conditions

Im trying to combine Cerain group information, but the way the data of type A and type B is displayed is very different.

that im trying to figure out how to create a condition within a group according to instructions.

t


GROUP BY

click.employee_id, click.mode, asset.location, click.paper_size, asset.name

OR

click.mode, asset.location, click.paper_size, asset.name

HAVING click.employee_id> = 10000000


If employee_id is greater than 100000, it should be grouped only by the second condition, and not taking into account click.employee_id.

Thanx in advance

+3
source share
2 answers

How about using the CASE statement in GROUP BY

Sort of

GROUP BY

CASE WHEN click.employee_id > 100000 THEN 1 ELSE click.employee_id END , 
click.mode, 
asset.location, 
click.paper_size, 
asset.name
+3
source

I agree with @astander. However, one caveat ...

SQL , . , . , , , 100 000, CASE 1 , . , ,

then 00000001 else click.employee_id...

, - .

+1

Source: https://habr.com/ru/post/1778306/


All Articles