在SELECT中使用count(*)over(…)语句中的计算列

问题描述 投票:0回答:1

我在SQL Server Management Studio 2014中具有以下选择语句:

   SELECT main.car_descr
          ,vari.engineCode
          ,count(*) over(partition by vari.engineCode) as quant
    FROM dbspareparts.dbo.stock as stock

    inner join fiord.dbo.store as main on stock.[id_store]=main.[id_store]

    where quant>2

    order by quant desc

执行时,我在指令上得到“无效的列名”

where quant>2

为什么以及如何获得这项工作?

我需要使用count(*)over(...)语句,因为这只是另一个更长的查询的一部分。

谢谢!

select count sql-server-2014 calculated-columns
1个回答
0
投票
直到查询返回后,quan才被绑定为变量,因此您需要将其包装在内部查询中,然后才能对其进行过滤。
© www.soinside.com 2019 - 2024. All rights reserved.