0

我有一个看起来像这样的表(称为 StayDate):

ResaID      Date        RoomCategory    RateAmount
 1       2014-09-01         A              125
 1       2014-09-02         A              125
 1       2014-09-03         B              140
 2       2014-09-04         A              125
 2       2014-09-05         A              125
 2       2014-09-06         A              125
 2       2014-09-07         C              160
 2       2014-09-08         C              160

我需要的 SQL 语法的输出如下所示:

ResaID      Count        RoomCategory    RateAmount
 1            2             A              125
 1            1             B              140
 2            3             A              125
 2            2             C              160

任何人都可以帮助汇总上述数据所需的 SQL 语法吗?

4

1 回答 1

2

一种没有 GROUP BY 的方法:

SELECT DISTINCT ResaID, COUNT(*) OVER (PARTITION BY ResaID, RoomCategory, RateAmount) Count, RoomCategory, RateAmount
FROM StayDate
于 2014-10-14T15:44:05.770 回答