GROUP BY忽略属性 [英] GROUP BY ignoring an attribute

查看:107
本文介绍了GROUP BY忽略属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有这张桌子:

itemgroup |描述|价格
A,A,10
A,B,12
A,C,14
B,g,11
B,h,16

itemgroup | description | price
A, a, 10
A, b, 12
A, c, 14
B, g, 11
B, h, 16

现在我要像这样在一组中选择价格最高的行:

now i want to select the rows with the highest price in one group like this:

A,C,14
B,h,16

A, c, 14
B, h, 16

SQL查询(功能齐全)可以使我接近以下位置:

The SQL query (is fully functional) wich gets me near this is:

SELECT itemgroup, MAX( price ) 
FROM table
GROUP BY itemgroup

A,14岁
B,16

A, 14
B, 16

通过尝试此操作,我收到不是GROUP BY表达式"错误:

By trying this I get an "not a GROUP BY expression"-error:

SELECT itemgroup, description, MAX( price ) 
FROM table
GROUP BY itemgroup

我需要类似以下的伪查询:

I need something like this pseudo query:

SELECT itemgroup, IGNORE( description), MAX( price ) 
FROM table
GROUP BY itemgroup

我希望我能解释我的小问题.

I hope i could explain my little problem.

推荐答案

我通常会做类似的事情:

I normally end up doing something like:

SELECT t1.itemgroup, t1.description, t1.price
FROM table t1, 
    (SELECT itemgroup, MAX( price ) as price
     FROM table
     GROUP BY itemgroup) t2
WHERE t1.itemgroup = t2.itemgroup
AND t1.price = t2.price

这篇关于GROUP BY忽略属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆