如何删除复杂查询的结果

时间:2017-03-13 14:37:20

标签: sql sql-server

当我用select *替换delete时,我在第2行附近遇到语法错误。但我需要这个,因为我在where子句中引用它。那么如何删除此查询的结果?

select *
    from [PrimusGroup].[dbo].[PrmsBlotter] t
    where t.RunType = 'Backtesting'
      and not exists (
        select 1
        from [PrimusGroup].[dbo].[PrmsBlotter] i
        where i.RunType = 'Live'
          and i.BBox = t.BBox
          and convert(date,i.RunDateStart) = convert(date,t.TestDateFrom)
    )

1 个答案:

答案 0 :(得分:1)

正如@Gordon Linoff所说,用select *替换delete t

delete t
from [PrimusGroup].[dbo].[PrmsBlotter] t
where t.RunType = 'Backtesting'
  and not exists (
    select 1
    from [PrimusGroup].[dbo].[PrmsBlotter] i
    where i.RunType = 'Live'
      and i.BBox = t.BBox
      and convert(date,i.RunDateStart) = convert(date,t.TestDateFrom)
)