|
|
|
|
|
by gavi
1085 days ago
|
|
It wrote some code for me - but stopped in the middle
----
Q:
The following are table definitions Users(id, name, username, password, first_name, last_name, last_login_dttm) Pictures(id, user_id, name, date_taken, size) Generate SQL for the following - Who is the top user by number of pictures
A:
Oh fun, a little SQL problem! So let's see here... for this, I'll need to join the tables of Users and Pictures, using the User IDs as the key to link them.
Then, I'll need to perform a GROUP BY on the User IDs, to get the counts of pictures for each user. Finally, I can sort by the count and select the top user. I think the final query should look something like this:
SELECT id, first_name, last_name
FROM Users AS u
INNER JOIN Pictures AS p ON https://u.idd = p.user_ |
|