1 个表上有 2 个字段的 In 子句
我有一个查询:
SELECT
MAX(date),
logId,
computerId
FROM
logTable
WHERE logId IN ('1','2','3')
但我希望 IN 子句也像这样测试 computerId :
logId = '1' and computerId = '998874',
logId = '2' and计算机 ID = '334211', ...
如何做到这一点?
I have a query :
SELECT
MAX(date),
logId,
computerId
FROM
logTable
WHERE logId IN ('1','2','3')
But I want the IN clause test the computerId too like this :
logId = '1' and computerId = '998874',
logId = '2' and computerId = '334211',
...
How to do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您必须将
IN
语句替换为多个OR
语句。或者,如果您有很多条件,为它们创建一个内存表并连接可能会更具可读性在这些条件下
You would have to replace the
IN
statement with multipleOR
statementsAlternatively, if you have many conditions, it might be more readable to create an in-memory table for them and join on these conditions
我认为您不能使用
IN
子句来做到这一点。我认为你需要一个有条件的where。所以:I don't think you can do that with an
IN
clause. I think you need a conditional where. So:SQL Server 中的
IN
不支持元组。您可以使用EXISTS
和表表达式。 2008 语法如下。IN
in SQL Server does not support tuples. You can useEXISTS
and a table expression. 2008 syntax below.像这样:
Like this: