[英]How to exclude something from this mssql/php query?
I've got this: 我有这个:
SELECT TOP 100
IDNum,
IDName,
Nation,
(SELECT
SUM(Loyalty)
FROM
USERDATA
WHERE
USERDATA.Knights = KNIGHTS.IDNum
AND USERDATA.Authority IN(1, 2)
) as ClanLoyalty
FROM
KNIGHTS
ORDER BY
ClanLoyalty DESC
but I want to exclude Knights
(21 and 25)
so knights IDNum
21 and 25 WONT be included in that query ? 但我想排除Knights
(21 and 25)
所以该查询中包含骑士IDNum
21岁和25岁?
How to exclude them ? 如何排除它们?
Wouldn't this be a simple where clause on your outer query? 这不是您的外部查询中的简单where子句吗?
SELECT TOP 100
IDNum,
IDName,
Nation,
(SELECT
SUM(Loyalty)
FROM
USERDATA
WHERE
USERDATA.Knights = KNIGHTS.IDNum
AND USERDATA.Authority IN(1, 2)
) as ClanLoyalty
FROM
KNIGHTS
where
knights.idnum not in (21,22)
ORDER BY
ClanLoyalty DESC
If you exclude it from the main query, they won't be matched on the inner query either as you have them joining on the IDNum field anyhow. 如果您将其从主查询中排除,则无论如何它们都不会在内部查询中匹配,因为无论如何它们都已加入IDNum字段。
On that note, you might also want to take a read of this Q&A that I put together which covers off a lot of SQL like this. 关于这一点,您可能还想阅读一下我整理的这份问答,其中涵盖了许多类似这样的SQL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.