Mysql查询 - 计算连接表上已建立的行[关闭]

I have two tables

First one: Offers

id user_id user_data

The second one: Orders

id user_id

order_data

Now, the goal is, to get the list of the OFFERS including the count of the orders table, where orders.user_id == offers.user_id

the result must be:

id user_id orders_count


Thank you in advance!

You have all the ingredients, it sounds like you just need to write the SQL. It would probably be something like:

select
a.id, a.user_id, count(*)
from offers a
inner join orders b on
a.user_id = b.user_id
group by a.id, a.user_id;