我需要在“派对”选择中添加选项where
。
这是我的工作代码:
SELECT p.id, (
SELECT COUNT( * )
FROM accounts
WHERE party = p.id
) AS u_count, p.title, p.slogan, p.owner, u.nickname, p.candidat, c.nickname, p.register_date
FROM party p
LEFT OUTER JOIN accounts u ON p.owner = u.id
LEFT OUTER JOIN accounts c ON p.candidat = c.id
此案例不起作用:( WHERE确认= 1 )
SELECT p.id, (
SELECT COUNT( * )
FROM accounts
WHERE party = p.id
) AS u_count, p.title, p.slogan, p.owner, u.nickname, p.candidat, c.nickname, p.register_date
FROM party p WHERE confirmed = 1
LEFT OUTER JOIN accounts u ON p.owner = u.id
LEFT OUTER JOIN accounts c ON p.candidat = c.id
答案 0 :(得分:2)
语法必须为select ... from .. join ... on ... where ...
SELECT p.id, (
SELECT COUNT( * )
FROM accounts
WHERE party = p.id
) AS u_count, p.title, p.slogan, p.owner, u.nickname, p.candidat, c.nickname, p.register_date
FROM party p LEFT OUTER JOIN accounts u ON p.owner = u.id
LEFT OUTER JOIN accounts c ON p.candidat = c.id
WHERE confirmed = 1