如何在OVER中使用COUNT子句?

时间:2013-01-16 15:28:59

标签: sql-server-express

我目前是sql查询语言的初学者,我目前正努力让以下查询起作用:

USE test;
GO
SELECT deal_type, price_type, 
    COUNT(deal_type) OVER(PARTITION BY deal_type) AS "Count1"
,COUNT(price_type) OVER(PARTITION BY deal_type) AS "Count2"  
FROM deal_price
WHERE deal_type = "rmbs", "Abs"
GO

我目前收到错误(“msg 156”)

所需的输出如下所示:

--deal_type, price_type, count_1
--rmbs, talk, 23
--rmbs, cvr, 40
--abs, talk, 40 

非常感谢任何帮助。谢谢。

1 个答案:

答案 0 :(得分:0)

使用In-clause

USE test;
GO
SELECT deal_type, price_type, 
COUNT(deal_type) OVER(PARTITION BY deal_type) AS 'Count1',
COUNT(price_type) OVER(PARTITION BY deal_type) AS 'Count2'  
FROM deal_price
WHERE deal_type in ('rmbs', 'Abs')
GO