I want to know to how many lists a user is assigned in average.
User
====
id
name
Lists_Users
===========
user_id
list_id
List
====
id
title
Is there a good way of receiving this number via SQL?
|
I want to know to how many lists a user is assigned in average.
Is there a good way of receiving this number via SQL? |
|||||
|
|
You only need the counts from the 2 tables and a division:
If you want more statistical information, you can write it using derived tables:
|
||||
|
|
|
I have no idea which RDBMS you are using, but on SQL Server using CTEs (Common Table Expression) it might look like something similar:
There must also be dozen of other (better?) ways of doing this... |
|||||||||
|