SQL多表查询统计数量

2024-11-24 01:46:52
推荐回答(2个)
回答1:

select *,(select count(u_id) from h_travel_line where u_id = a.u_id) 已线路数
from h_travel a
如此便可

回答2:

SELECT c.ttt AS 已线路数, h_travel.*
FROM h_travel INNER JOIN
(SELECT COUNT(*) AS ttt, u_id
FROM h_travel_line
GROUP BY STID) c
ON h_travel.u_id =c.u_id