Tag:phpmysql
Article From:https://segmentfault.com/q/1010000012154526
Question:

Now there are two tables
ATable (questionnaire): ID, title
BTable (questionnaire completed by users): ID, a.id, user_id

Now we need to count the number of users answered by each questionnaire. How do we do this?

I can do two queries, but one sentence is not acceptable.

Forget to say, B table data is not necessarily

Answer 0:

select title, count(user_id) total from a left join b on a.id=b.aid group by(b.aid) order by total DESC

bIs there any data that does not affect the table

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *