Jump to content

how to group results


shaddf
Go to solution Solved by Psycho,

Recommended Posts

how can i get all tha apps of each player from this table by seasonid for a particular ShortName (tournament)?eg all the Apps for houseid 12  in friendly in 1 column and NDIV V in another etc.Not tjat seasons can be different

+---------+-----------+------+----------+------------+------+----+
| houseid | ShortName | logo | SeasonID | SeasonName | Apps | Gl |
+---------+-----------+------+----------+------------+------+----+
|       5 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|      18 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|      13 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|       6 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|       1 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|      14 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|       7 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|       2 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|      15 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|       8 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|       3 | NDIV V    | NULL |       12 | 2016/17    |    1 |  1 |
|      16 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|       9 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|       4 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|      17 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|      10 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|       5 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|      18 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|      11 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|       6 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|      12 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|       7 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|      13 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|       8 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|       1 | Friendly  | NULL |       12 | 2016/17    |    1 |  3 |
|      14 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|       9 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|       2 | Friendly  | NULL |       12 | 2016/17    |    1 |  1 |
|      15 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|      10 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|       3 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|      16 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|      11 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
|       4 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|      17 | Friendly  | NULL |       12 | 2016/17    |    1 |  0 |
|      12 | NDIV V    | NULL |       12 | 2016/17    |    1 |  0 |
+---------+-----------+------+----------+------------+------+----+

i have tried this but itgets me 1 row only:

 

SELECT houseid as P_id, ShortName, logo, SeasonName, SUM(Apps) as Apps1, SUM(Gl) as Gls FROMtble stats;



Edited by shaddf
Link to comment
Share on other sites

  • Solution

Use GROUP BY. You need to group by all the unique fields - i.e. those that are not included in aggregate functions such as SUM()

 

SELECT houseid as P_id, ShortName, logo, SeasonName, SUM(Apps) as Apps1, SUM(Gl) as Gls
FROM tble_stats
GROUP BY houseid, ShortName, logo, SeasonName

 

You state you want the values for each houseid and Shortname. But, you also have logo and SeasonName - so you would need to group by those as well in case they can be different for the same houseid/Shortname values. If they cannot be different - then your structure is wrong.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.