我有以下格式的数据:
Table: MountHeights
ID | Height| Type | ItemCode | Context
--------------------------------------------
1 | 15 | max | BD1896-1W | exterior
2 | 12 | max | BD1896-1W | insect
3 | 18 | max | BD1896-1W | interior
4 | 13 | max | BD14120-1W | exterior
5 | 10 | max | BD14120-1W | insect
6 | 15 | max | BD14120-1W | interior
每个商品代码都有多行。
我试图找出一个办法让max(Height)
每个ItemCode
在Type
=“最大”,出于某种原因,我不能完全绕到我的头,我应该如何引用表本身。
我希望结果遵循以下原则:
Results:
max(Height)| ItemCode
---------------------------
18 | BD1896-1W
15 | BD14120-1W
我怎么做?
此处无需自参考表。
SELECT `ItemCode`, MAX( `height` )
FROM `MountHeights`
WHERE `Type`= 'max'
GROUP BY `ItemCode`
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句