Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mysql> SELECT * FROM players;
- +-----------+---------+----------------------+----------------------+-----------------+------------------------------+-----------------------+---------------------+
- | player_id | team_id | player_name | player_jersey_number | player_position | player_email | player_contact_number | player_timestamp |
- +-----------+---------+----------------------+----------------------+-----------------+------------------------------+-----------------------+---------------------+
- | 1 | 4 | Popoy Alfonso | 2 | | popoyalfonso@gmail.com | 09263453234 | 2015-08-05 00:48:10 |
- | 2 | 4 | Karlo Ripas | 10 | | karloripas@yahoo.com | 09212354324 | 2015-08-05 00:50:03 |
- | 3 | 4 | VHaughn Von | 32 | | von@outlook.com | 09361234565 | 2015-08-05 00:51:00 |
- | 4 | 4 | Lordie Zalbahe | 23 | | lordiezalbahe@gmail.com | 09391222334 | 2015-08-05 00:52:42 |
- | 5 | 4 | Jigs Selda | 8 | | jigsselda@gmail.com | 09325566323 | 2015-08-05 00:53:36 |
- | 6 | 4 | Rhan Garniel | 3 | | rhangarniel@ymail.com | 09129503400 | 2015-08-05 00:54:20 |
- | 7 | 5 | Johnritz Rodriguez | 11 | | johnritz@gmail.com | 09231112346 | 2015-08-05 00:56:02 |
- | 8 | 5 | Garret Van Sarmiento | 7 | | garretvansarmiento@gmail.com | 09264565600 | 2015-08-05 00:56:53 |
- | 9 | 5 | Lester Selda Lineses | 12 | | lesterlineses@yahoo.com | 09068746354 | 2015-08-05 00:57:47 |
- | 10 | 5 | Laurence Lineses | 44 | | laurencelineses@yahoo.com | 09847354672 | 2015-08-05 00:59:33 |
- | 11 | 5 | Xandrix Buendia | 1 | | xandrixbuendia@yahoo.com | 09234665590 | 2015-08-05 01:00:12 |
- | 12 | 5 | Betoyskie Limpiada | 45 | | betoyskie@outlook.com | 09213456667 | 2015-08-05 01:01:15 |
- +-----------+---------+----------------------+----------------------+-----------------+------------------------------+-----------------------+---------------------+
- mysql> SELECT * FROM teams;
- +---------+-----------+----------------------+---------------------+
- | team_id | season_id | team_name | team_timestamp |
- +---------+-----------+----------------------+---------------------+
- | 4 | 1 | Quiapo A | 2015-08-05 00:30:13 |
- | 5 | 1 | Quiapo B | 2015-08-05 00:30:25 |
- | 6 | 1 | Balik-Balik Warriors | 2015-08-05 00:31:13 |
- | 7 | 1 | Adamson Falcons | 2015-08-05 00:31:42 |
- | 8 | 1 | Pasay Flooders | 2015-08-05 00:32:04 |
- | 9 | 1 | Marina Dragons | 2015-08-05 00:32:22 |
- | 10 | 1 | MDC Archers | 2015-08-05 00:33:12 |
- | 11 | 2 | Quiapo A | 2015-08-05 00:34:25 |
- | 12 | 2 | Quiapo B | 2015-08-05 00:34:38 |
- | 13 | 2 | Marikina Eagels | 2015-08-05 00:35:11 |
- | 14 | 2 | TIP Steallers | 2015-08-05 00:35:32 |
- | 15 | 2 | Gasan Blue Eagles | 2015-08-05 00:36:12 |
- +---------+-----------+----------------------+---------------------+
- mysql> SELECT * FROM seasons;
- +-----------+-------------+----------------------+---------------------+
- | season_id | season_name | season_event_name | season_timestamp |
- +-----------+-------------+----------------------+---------------------+
- | 1 | Season 1 | Summer Games | 2015-08-05 00:23:15 |
- | 2 | Season 2 | Aniversary Sportfest | 2015-08-05 00:25:10 |
- +-----------+-------------+----------------------+---------------------+
- SELECT
- teams.team_name,
- (
- SELECT COUNT(*)
- FROM teams
- INNER JOIN players
- ON teams.team_id = players.team_id
- ) as num_of_players,
- teams.team_timestamp
- FROM teams
- INNER JOIN seasons
- ON seasons.season_id = teams.season_id
- GROUP BY teams.team_name;
- +----------------------+----------------+---------------------+
- | team_name | num_of_players | team_timestamp |
- +----------------------+----------------+---------------------+
- | Adamson Falcons | 12 | 2015-08-05 00:31:42 |
- | Balik-Balik Warriors | 12 | 2015-08-05 00:31:13 |
- | Gasan Blue Eagles | 12 | 2015-08-05 00:36:12 |
- | Marikina Eagels | 12 | 2015-08-05 00:35:11 |
- | Marina Dragons | 12 | 2015-08-05 00:32:22 |
- | MDC Archers | 12 | 2015-08-05 00:33:12 |
- | Pasay Flooders | 12 | 2015-08-05 00:32:04 |
- | Quiapo A | 12 | 2015-08-05 00:30:13 |
- | Quiapo B | 12 | 2015-08-05 00:30:25 |
- | TIP Steallers | 12 | 2015-08-05 00:35:32 |
- +----------------------+----------------+---------------------+
- +----------------------+----------------+---------------------+
- | team_name | num_of_players | team_timestamp |
- +----------------------+----------------+---------------------+
- | Adamson Falcons | 0 | 2015-08-05 00:31:42 |
- | Balik-Balik Warriors | 0 | 2015-08-05 00:31:13 |
- | Gasan Blue Eagles | 0 | 2015-08-05 00:36:12 |
- | Marikina Eagels | 0 | 2015-08-05 00:35:11 |
- | Marina Dragons | 0 | 2015-08-05 00:32:22 |
- | MDC Archers | 0 | 2015-08-05 00:33:12 |
- | Pasay Flooders | 0 | 2015-08-05 00:32:04 |
- | Quiapo A | 6 | 2015-08-05 00:30:13 |
- | Quiapo B | 6 | 2015-08-05 00:30:25 |
- | TIP Steallers | 0 | 2015-08-05 00:35:32 |
- +----------------------+----------------+---------------------+
- SELECT
- teams.team_name,
- COUNT(players.player_id) as num_of_players,
- teams.team_timestamp
- FROM test.teams
- JOIN test.players ON (players.team_id=teams.team_id)
- JOIN seasons ON (seasons.season_id = teams.season_id)
- GROUP BY teams.team_name;
- CREATE TABLE `player` (
- `player_id` int(11) DEFAULT NULL,
- `team_id` int(11) DEFAULT NULL,
- `player_name` varchar(25) DEFAULT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1
- 1 row in set (0.00 sec)
- CREATE TABLE `team` (
- `team_id` int(11) DEFAULT NULL,
- `season_id` int(11) DEFAULT NULL,
- `team_name` varchar(25) DEFAULT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1
- 1 row in set (0.00 sec)
- SELECT t1.team_id, t1.team_name,
- IFNULL(t2.num_players, 0) AS strength
- FROM team t1
- LEFT OUTER JOIN
- (SELECT team_id, COUNT(team_id) AS num_players
- FROM player
- GROUP BY team_id
- ) t2
- ON t1.team_id = t2.team_id
- ORDER BY strength DESC, team_name ASC;
- +---------+----------------------+----------+
- | team_id | team_name | strength |
- +---------+----------------------+----------+
- | 4 | Quiapo A | 6 |
- | 5 | Quiapo B | 6 |
- | 7 | Adamson Falcons | 0 |
- | 6 | Balik-Balik Warriors | 0 |
- | 15 | Gasan Blue Eagles | 0 |
- | 13 | Marikina Eagels | 0 |
- | 9 | Marina Dragons | 0 |
- | 10 | MDC Archers | 0 |
- | 8 | Pasay Flooders | 0 |
- | 11 | Quiapo A | 0 |
- | 12 | Quiapo B | 0 |
- | 14 | TIP Steallers | 0 |
- +---------+----------------------+----------+
- 12 rows in set (0.00 sec)
- mysql> SELECT * FROM player;
- +-----------+---------+----------------------+
- | player_id | team_id | player_name |
- +-----------+---------+----------------------+
- | 1 | 4 | Popoy Alfonso |
- | 2 | 4 | Karlo Ripas |
- | 3 | 4 | VHaughn Von |
- | 4 | 4 | Lordie Zalbahe |
- | 5 | 4 | Jigs Selda |
- | 6 | 4 | Rhan Garniel |
- | 7 | 5 | Johnritz Rodriguez |
- | 8 | 5 | Garret Van Sarmiento |
- | 9 | 5 | Lester Selda Lineses |
- | 10 | 5 | Laurence Lineses |
- | 11 | 5 | Xandrix Buendia |
- | 12 | 5 | Betoyskie Limpiada |
- +-----------+---------+----------------------+
- 12 rows in set (0.00 sec)
- mysql> SELECT * FROM team;
- +---------+-----------+----------------------+
- | team_id | season_id | team_name |
- +---------+-----------+----------------------+
- | 4 | 1 | Quiapo A |
- | 5 | 1 | Quiapo B |
- | 6 | 1 | Balik-Balik Warriors |
- | 7 | 1 | Adamson Falcons |
- | 8 | 1 | Pasay Flooders |
- | 9 | 1 | Marina Dragons |
- | 10 | 1 | MDC Archers |
- | 11 | 2 | Quiapo A |
- | 12 | 2 | Quiapo B |
- | 13 | 2 | Marikina Eagels |
- | 14 | 2 | TIP Steallers |
- | 15 | 2 | Gasan Blue Eagles |
- +---------+-----------+----------------------+
- 12 rows in set (0.00 sec)
- mysql>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement