sql - Get all entries from one table together with the count of these entries in another table -


I have 3 tables:

  • The user (id, name, ... < / Li>
  • Item (id, name, ...)
  • download (user_id, item_id, ...)

How do I get all the users With the number of downloads they have?

How do I get all the users together With the number of downloads?

Use:

  SELECT u.name, COUNT (d.user_id) users 'num_downloaded' and download the OIN S on d.user_id = u.user_id GROUP by u.name  

If you want to see how many times a user has downloaded a particular item:

Select username 'user_name', name 'item_name', COUNT (DUGEER_ID), and download the user from 'UN downloads'. D.user_id = u.user_id iitit_id = d on iits Add the .item_id group to U.Name, i.name

Comments

Popular posts from this blog

Is there an open source WebSockets (JavaScript) XMPP library? -

java - Is there an object like a "Set" that can contain only unique string values, but also contain a count on the number of occurrences of the string value? -

iphone - How do I make a UIPickerView in a UIActionSheet -