我需要在我的sql请求中添加一个选项“where”

时间:2016-08-01 06:32:09

标签: mysql sql

我需要在“派对”选择中添加选项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

1 个答案:

答案 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