TSQL子查询来自

时间:2018-04-10 20:54:58

标签: sql-server tsql

我正在尝试做一个应该有效的子查询,但我在syntex中遗漏了一些东西。

我在尝试:

Resolve

我在内部附近得到的语法不正确。

这有效:

select * 
from (select * from (select *, row_number() over (partition by number,system order by number,system) as rc from [dbo].[info]) tk0 where tk0.rc =1)  tkt
 inner join [dbo].[QUEUES] pq
 on pq.[QUEUE_NAME] = tkt.[QueueName] inner join [dbo].PLATFORMS] pl
 on pl.id = pq.platform_id

1 个答案:

答案 0 :(得分:3)

错过了[在平台线上。以下应该有效:

select * 
from 
    (
        select * 
        from 
            (
                select 
                    *, row_number() over (partition by number,system order by number,system) as rc 
                from [dbo].[info]
            ) tk0 
        where tk0.rc =1
    )  tkt
 inner join [dbo].[QUEUES] pq
 on pq.[QUEUE_NAME] = tkt.[QueueName] 
 inner join [dbo].[PLATFORMS] pl --correction done here
 on pl.id = pq.platform_id

你也可以在join中编写你的where子句:

select * 
from 
    (
    select 
        *, row_number() over (partition by number,system order by number,system) as rc 
    from [dbo].[info]

    )  tkt
 inner join [dbo].[QUEUES] pq
 on pq.[QUEUE_NAME] = tkt.[QueueName]  and tkt.rc =1
 inner join [dbo].[PLATFORMS] pl
 on pl.id = pq.platform_id