Project Coding
Project Coding
2861]
(c) Microsoft Corporation. All rights reserved.
C:\Users\V.MANOHAR>mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.34 MySQL Community Server - GPL
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> -- CHALLENGES
mysql> -- FIND 5 OLDEST USERS
mysql> SELECT * FROM USERS;
+-----+-----------------------+---------------------+
| id | username | created_at |
+-----+-----------------------+---------------------+
| 1 | Kenton_Kirlin | 2017-02-16 18:22:11 |
| 2 | Andre_Purdy85 | 2017-04-02 17:11:21 |
| 3 | Harley_Lind18 | 2017-02-21 11:12:33 |
| 4 | Arely_Bogan63 | 2016-08-13 01:28:43 |
| 5 | Aniya_Hackett | 2016-12-07 01:04:39 |
| 6 | Travon.Waters | 2017-04-30 13:26:14 |
| 7 | Kasandra_Homenick | 2016-12-12 06:50:08 |
| 8 | Tabitha_Schamberger11 | 2016-08-20 02:19:46 |
| 9 | Gus93 | 2016-06-24 19:36:31 |
| 10 | Presley_McClure | 2016-08-07 16:25:49 |
| 11 | Justina.Gaylord27 | 2017-05-04 16:32:16 |
| 12 | Dereck65 | 2017-01-19 01:34:14 |
| 13 | Alexandro35 | 2017-03-29 17:09:02 |
| 14 | Jaclyn81 | 2017-02-06 23:29:16 |
| 15 | Billy52 | 2016-10-05 14:10:20 |
| 16 | Annalise.McKenzie16 | 2016-08-02 21:32:46 |
| 17 | Norbert_Carroll35 | 2017-02-06 22:05:43 |
| 18 | Odessa2 | 2016-10-21 18:16:56 |
| 19 | Hailee26 | 2017-04-29 18:53:40 |
| 20 | Delpha.Kihn | 2016-08-31 02:42:30 |
| 21 | Rocio33 | 2017-01-23 11:51:15 |
| 22 | Kenneth64 | 2016-12-27 09:48:17 |
| 23 | Eveline95 | 2017-01-23 23:14:19 |
| 24 | Maxwell.Halvorson | 2017-04-18 02:32:44 |
| 25 | Tierra.Trantow | 2016-10-03 12:49:21 |
| 26 | Josianne.Friesen | 2016-06-07 12:47:01 |
| 27 | Darwin29 | 2017-03-18 03:10:07 |
| 28 | Dario77 | 2016-08-18 07:15:03 |
| 29 | Jaime53 | 2016-09-11 18:51:57 |
| 30 | Kaley9 | 2016-09-23 21:24:20 |
| 31 | Aiyana_Hoeger | 2016-09-29 20:28:12 |
| 32 | Irwin.Larson | 2016-08-26 19:36:22 |
| 33 | Yvette.Gottlieb91 | 2016-11-14 12:32:01 |
| 34 | Pearl7 | 2016-07-08 21:42:01 |
| 35 | Lennie_Hartmann40 | 2017-03-30 03:25:22 |
| 36 | Ollie_Ledner37 | 2016-08-04 15:42:20 |
| 37 | Yazmin_Mills95 | 2016-07-27 00:56:44 |
| 38 | Jordyn.Jacobson2 | 2016-05-14 07:56:26 |
| 39 | Kelsi26 | 2016-06-08 17:48:08 |
| 40 | Rafael.Hickle2 | 2016-05-19 09:51:26 |
| 41 | Mckenna17 | 2016-07-17 17:25:45 |
| 42 | Maya.Farrell | 2016-12-11 18:04:45 |
| 43 | Janet.Armstrong | 2016-10-06 07:57:44 |
| 44 | Seth46 | 2016-07-07 11:40:27 |
| 45 | David.Osinski47 | 2017-02-05 21:23:37 |
| 46 | Malinda_Streich | 2016-07-09 21:37:08 |
| 47 | Harrison.Beatty50 | 2016-09-02 03:48:38 |
| 48 | Granville_Kutch | 2016-06-26 03:10:22 |
| 49 | Morgan.Kassulke | 2016-10-30 12:42:31 |
| 50 | Gerard79 | 2016-08-23 19:47:44 |
| 51 | Mariano_Koch3 | 2017-04-17 14:14:46 |
| 52 | Zack_Kemmer93 | 2017-01-01 05:58:22 |
| 53 | Linnea59 | 2017-02-07 07:49:34 |
| 54 | Duane60 | 2016-12-21 04:43:38 |
| 55 | Meggie_Doyle | 2017-04-04 12:17:34 |
| 56 | Peter.Stehr0 | 2016-08-22 18:05:42 |
| 57 | Julien_Schmidt | 2017-02-02 23:12:48 |
| 58 | Aurelie71 | 2016-05-31 06:20:57 |
| 59 | Cesar93 | 2016-10-18 16:42:43 |
| 60 | Sam52 | 2017-03-30 22:03:45 |
| 61 | Jayson65 | 2016-10-14 19:10:53 |
| 62 | Ressie_Stanton46 | 2016-12-20 15:09:09 |
| 63 | Elenor88 | 2016-05-08 01:30:41 |
| 64 | Florence99 | 2016-10-06 23:08:31 |
| 65 | Adelle96 | 2016-10-01 00:37:57 |
| 66 | Mike.Auer39 | 2016-07-01 17:36:15 |
| 67 | Emilio_Bernier52 | 2016-05-06 13:04:30 |
| 68 | Franco_Keebler64 | 2016-11-13 20:09:27 |
| 69 | Karley_Bosco | 2016-06-24 23:38:52 |
| 70 | Erick5 | 2017-04-05 23:44:47 |
| 71 | Nia_Haag | 2016-05-14 15:38:50 |
| 72 | Kathryn80 | 2016-10-11 09:01:57 |
| 73 | Jaylan.Lakin | 2016-06-10 23:58:52 |
| 74 | Hulda.Macejkovic | 2017-01-25 17:17:28 |
| 75 | Leslie67 | 2016-09-21 05:14:01 |
| 76 | Janelle.Nikolaus81 | 2016-07-21 09:26:09 |
| 77 | Donald.Fritsch | 2017-01-07 10:05:41 |
| 78 | Colten.Harris76 | 2016-10-10 02:38:53 |
| 79 | Katarina.Dibbert | 2016-11-03 13:14:11 |
| 80 | Darby_Herzog | 2016-05-06 00:14:21 |
| 81 | Esther.Zulauf61 | 2017-01-14 17:02:34 |
| 82 | Aracely.Johnston98 | 2016-07-25 18:49:10 |
| 83 | Bartholome.Bernhard | 2016-11-06 02:31:23 |
| 84 | Alysa22 | 2017-01-01 17:44:43 |
| 85 | Milford_Gleichner42 | 2017-04-30 07:50:51 |
| 86 | Delfina_VonRueden68 | 2017-03-21 12:02:14 |
| 87 | Rick29 | 2017-02-24 11:25:08 |
| 88 | Clint27 | 2016-06-02 21:40:10 |
| 89 | Jessyca_West | 2016-09-14 23:47:05 |
| 90 | Esmeralda.Mraz57 | 2017-03-03 11:52:27 |
| 91 | Bethany20 | 2016-06-03 23:31:53 |
| 92 | Frederik_Rice | 2016-07-06 21:56:29 |
| 93 | Willie_Leuschke | 2017-02-15 01:40:53 |
| 94 | Damon35 | 2016-10-31 14:44:27 |
| 95 | Nicole71 | 2016-05-09 17:30:22 |
| 96 | Keenan.Schamberger60 | 2016-08-28 14:57:28 |
| 97 | Tomas.Beatty93 | 2017-02-11 11:38:55 |
| 98 | Imani_Nicolas17 | 2017-01-31 22:59:34 |
| 99 | Alek_Watsica | 2016-12-10 07:43:58 |
| 100 | Javonte83 | 2017-03-27 22:06:37 |
+-----+-----------------------+---------------------+
100 rows in set (0.00 sec)
mysql> -- 7. Find the number of users who have liked every single photo on the
site?
mysql> SELECT
-> USERS.ID AS USER_ID,
-> USERS.USERNAME,
-> COUNT(*) AS TOTAL_USER_LIKES
-> FROM USERS
-> JOIN LIKES
-> ON USERS.ID = LIKES.USER_ID
-> GROUP BY USERS.ID
-> HAVING TOTAL_USERS_LIKES = (
-> SELECT COUNT(*) FROM PHOTOS
-> );
ERROR 1054 (42S22): Unknown column 'TOTAL_USERS_LIKES' in 'having clause'
mysql> SELECT
-> USERS.ID AS USER_ID,
-> USERS.USERNAME,
-> COUNT(*) AS TOTAL_USER_LIKES
-> FROM USERS
-> JOIN LIKES
-> ON USERS.ID = LIKES.USER_ID
-> GROUP BY USERS.ID
-> HAVING TOTAL_USER_LIKES = (
-> SELECT COUNT(*) FROM PHOTOS
-> );
+---------+--------------------+------------------+
| USER_ID | USERNAME | TOTAL_USER_LIKES |
+---------+--------------------+------------------+
| 5 | Aniya_Hackett | 257 |
| 14 | Jaclyn81 | 257 |
| 21 | Rocio33 | 257 |
| 24 | Maxwell.Halvorson | 257 |
| 36 | Ollie_Ledner37 | 257 |
| 41 | Mckenna17 | 257 |
| 54 | Duane60 | 257 |
| 57 | Julien_Schmidt | 257 |
| 66 | Mike.Auer39 | 257 |
| 71 | Nia_Haag | 257 |
| 75 | Leslie67 | 257 |
| 76 | Janelle.Nikolaus81 | 257 |
| 91 | Bethany20 | 257 |
+---------+--------------------+------------------+
13 rows in set (0.01 sec)
mysql>