All pastes #90515 Raw Edit

Stuff

public sql v1 · immutable
#90515 ·published 2006-07-17 19:23 UTC
rendered paste body
SELECT	u.ID AS UserID,	u.Name AS UserName,	sum(a.Points) AS UserPointsFROM	users AS u	LEFT JOIN user_awards AS ua ON ua.UserID = u.ID	INNER JOIN awards AS a ON a.ID = ua.AwardIDGROUP BY	u.IDORDER BY	UserPoints DESC;+--------+----------------+------------+| UserID | UserName       | UserPoints |+--------+----------------+------------+| 1      | Megaman        | 34         || 3      | Mr. Incredible | 20         || 2      | Superdude      | 16         || 4      | Monkey         | 10         || 5      | Batman         | 3          || 6      | George W. Bush | 1          |+--------+----------------+------------+6 rows in set (0.00 sec)mysql> select * from users;+----+----------------+| ID | Name           |+----+----------------+| 1  | Megaman        || 2  | Superdude      || 3  | Mr. Incredible || 4  | Monkey         || 5  | Batman         || 6  | George W. Bush || 7  | FooMan         |+----+----------------+7 rows in set (0.01 sec)mysql>