Sql server 在表中选择多个列
我想选择内部表中出现的guid和uuid,但SQL Server 2016中不允许使用以下语法,我应该怎么做Sql server 在表中选择多个列,sql-server,sql-server-2016,Sql Server,Sql Server 2016,我想选择内部表中出现的guid和uuid,但SQL Server 2016中不允许使用以下语法,我应该怎么做 select * from myTable where (guid, uuid) in (select max(guid) as maxguid, convert(nvarchar(max), uuid) as uuid from myTable group by convert(nvarch
select *
from myTable
where (guid, uuid) in (select max(guid) as maxguid, convert(nvarchar(max), uuid) as uuid
from myTable
group by convert(nvarchar(max), uuid)
)
我看到了其他答案,例如,但我的内部表中有一个group by语句,不知道如何使用它们。您可以使用子查询和联接,类似于
select
myTable.*
from
myTable join
(
select
max(guid) as maxguid,
convert(nvarchar(max), uuid) as uuid
from
myTable
group by
convert(nvarchar(max), uuid)
) x
on
x.maxguid = myTable.guid and
x.uuid = myTable.uuid
将分组放入内部子查询中,并对多个列使用exists
select * from myTable
where exists
(select 1
from (select max(guid) as maxguid, convert(nvarchar(max), uuid) as uuid
from myTable
group by convert(nvarchar(max), uuid)) innerTable
where myTable.guid = innerTable.maxguid
and myTable.uuid = innerTable.uuid)
为什么要对guid执行max?我想guid是一个字符串。你想在这儿洗衣服吗?如果myTable中有多个匹配项,是否全部选中?