Comments - GROUP BY

5 months, 2 weeks ago keke magdales

Hi,

I notice I got a different result between those two request :

A°/ SELECT wins, COUNT(*) FROM plays GROUP BY wins; B°/ SELECT wins, COUNT(*) FROM plays GROUP BY 'wins';

On A°/ i got the normal result : +------+----------+

winsCOUNT(*)

+------+----------+

31
51
82

+------+----------+

As for B° I got something strange : +------+----------+

winsCOUNT(*)

+------+----------+

54

+------+----------+

Could someone tell me the reason ?

Many thanks !

 
5 months, 2 weeks ago Ian Gilfillan

Because 'wins' in single quotes doesn't exist, so the latter query is essentially the same as

SELECT wins, COUNT(*) FROM plays GROUP BY NULL;
+------+----------+
| wins | COUNT(*) |
+------+----------+
|    5 |        4 |
+------+----------+

You may have been trying to use backticks (see Identifier Names):

SELECT wins, COUNT(*) FROM plays GROUP BY `wins`;
+------+----------+
| wins | COUNT(*) |
+------+----------+
|    3 |        1 |
|    5 |        1 |
|    8 |        2 |
+------+----------+
 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.