对不起,我知道在Sql Server中合并是完全不同的,但我想不出还有什么可以称之为。
我有一个用户定义的表类型,看起来像
-------------------------------------------------------------------
| Id | Foreign Key | Height | Weight | Width | Length |
-------------------------------------------------------------------
| 01 | 1256 | 12.2 | 15.8 | 14.5 | 15 |
| 02 | 1256 | 18.2 | 15.8 | 25.8 | 28 |
| 03 | 1258 | 14.5 | 11.3 | 56.6 | 32 |
| 04 | 1258 | 14.5 | 1.85 | 32.9 | 64 |
| 05 | 1216 | 25.3 | 16.2 | 12.5 | 86 |
-------------------------------------------------------------------
我希望能够进行查询或者某些东西给我一个与它相关的最低高度,重量,宽度和长度的外键,所以我有类似的东西
------------------------------------------------------------
| Foreign Key | Height | Weight | Width | Length |
------------------------------------------------------------
| 1256 | 12.2 | 15.8 | 14.5 | 15 |
| 1258 | 14.5 | 1.85 | 32.9 | 32 |
| 1216 | 25.3 | 16.2 | 12.5 | 86 |
------------------------------------------------------------
Sql Server中是否有任何功能可以实现这一点,或者任何人都可以指出任何可能有用的资源?
由于
答案 0 :(得分:3)
根据您的预期输出,这应该可以解决问题:
SELECT [Foreign Key], MIN(Height) AS Height, MIN(Weight) AS Weight,
MIN(Length) AS Length
FROM @YourTableVar
GROUP BY [Foreign Key]
答案 1 :(得分:0)
可以直接选择列的最小值:
select
[Foreign Key],
MIN(Height) AS MinHeight,
MIN(Weight) AS MinWeight,
MIN(Length) AS MinLength
FROM
Table
GROUP BY
[Foreign Key]