0

ここにコードがあります

SELECT username,count(username) FROM users WHERE status = '1' // $vuser to get the verified user only (it's the main query)

SELECT username FROM banned_users WHERE username = $vuser  // if yes $bad_user is true else false

1 つの SQL クエリで、banned_users に存在しない検証済みのユーザーのみを選択/カウントすることは可能ですか?

任意のアイデアをお願いします?

4

2 に答える 2

4
SELECT u.username, count(u.username) 
FROM users u
left outer join banned_users b on b.username = u.username
WHERE u.status = '1'
AND b.username is null
GROUP BY u.username
于 2013-05-20T10:44:34.353 に答える
1

ネストされたクエリを試してください:

SELECT username, COUNT(username) // Selects the `username` and `COUNT(username)` columns
FROM users // From the `users` table
WHERE status = '1' // Where its `status` is '1'
AND username NOT IN (SELECT b.username FROM banned_users b) // And its `username` is not at `username` column in the `banned_users` table
于 2013-05-20T10:49:02.983 に答える