How can I remove the shortcut for the SELECT clause used in GROUP BY?

I have a request:

SELECT
  ...
  (some expression) AS Country
FROM
  Sometable
  ...
GROUP BY Country;
  • Sometablehas a column with a name Country(this cannot be changed).
  • One of the result columns is called Country(this also cannot be changed).

It works (I want to GROUP BYapply to the result column, and MySQL also understands this).

But he gives a warning:

Warning: Column 'Country' in group statement is ambiguous

, GROUP BY. , , ( : Sometable.Country). , , , . - Select.Country, , , , - SELECT, , .

, , ( ), , ( ).

+3
2
SELECT a,b,c,d, country2 AS country FROM (
   SELECT
  a,b,c,d,
  (some expression) AS Country2
  FROM
    Sometable
    ...
  GROUP BY Country ) s;
+1

, , :

Group By (some expression)

I.e., By. . - /.

+1

All Articles