如何在mysql中组合这两个查询?
select count(*) as entry_count from tbl_entries where user_id = x
和
select username, avatar from tbl_users where user_id = x
我想要一个结合了这两个查询结果的结果。请帮帮我们!
谢谢!
答案 0 :(得分:6)
select username,
avatar,
(select count(*) from tbl_entries where user_id = x) as entry_count
from tbl_users
where user_id = x
答案 1 :(得分:1)
select username,
avatar,
(select count(*) from tbl_entries where user_id = x) AS cnt
from tbl_users
where user_id = x
答案 2 :(得分:0)
试试这个:
SELECT a.username,
a.avatar,
COUNT(*) as entry_count,
FROM tbl_Users a LEFT JOIN tbl_entries b ON
a.user_ID = b.user_ID
WHERE a.user_ID = x
GROUP BY a.username
答案 3 :(得分:0)
试试这个:
SELECT U.username, U.avatar,
count(*) AS entry_count
FROM tbl_users AS U
LEFT JOIN tbl_entries AS E ON U.user_id = E.user_id
WHERE user_id = x
GROUP BY U.user_id;
答案 4 :(得分:0)
SELECT用户名, 化身, (从tbl_entries中选择count(*),其中user_id = U.user_id)AS cnt 来自tbl_users AS U. WHERE user_id = x