导致此错误的原因是:')'sql附近的语法不正确

时间:2021-07-05 00:59:19

Whats wrong with the sql syntax below?

以下sql语法有什么问题?

  /*distinct number of person numbers with D11*/
 select distinct person_number from

 /*select which ones of the 1000 have D11*/
 (select event, person_number
  from table
 where event = 'D11' and person_number in 
 (
 /*top 1000 */
 select distinct top (1000) person_number
  from table with (nolock)
 where client = 3
 ))

1 个解决方案

#1


3  

Alias the subquery:

别名子查询:

/*distinct number of person numbers with D11*/
SELECT DISTINCT person_number
FROM
    /*select which ones of the 1000 have D11*/
    (
    SELECT event
        ,person_number
    FROM TABLE
    WHERE event = 'D11'
        AND person_number IN (
            /*top 1000 */
            SELECT DISTINCT TOP (1000) person_number
            FROM TABLE
            WITH (NOLOCK)
            WHERE client = 3
            ) a
    ) b

duplicate of Nested select statement in SQL Server

SQL Server中嵌套的select语句的副本

#1


3  

Alias the subquery:

别名子查询:

/*distinct number of person numbers with D11*/
SELECT DISTINCT person_number
FROM
    /*select which ones of the 1000 have D11*/
    (
    SELECT event
        ,person_number
    FROM TABLE
    WHERE event = 'D11'
        AND person_number IN (
            /*top 1000 */
            SELECT DISTINCT TOP (1000) person_number
            FROM TABLE
            WITH (NOLOCK)
            WHERE client = 3
            ) a
    ) b

duplicate of Nested select statement in SQL Server

SQL Server中嵌套的select语句的副本