查询问题

daijingjie2002 2004-04-19 09:02:03
如下表
a b c
w 0.1 1
w 0.3 2
w 0.2 3
w 0.6 4
A列为编码,B列为单价,C列为月分,如何查询出最大的一个月的单价
...全文
50 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
long0104 2004-04-19
  • 打赏
  • 举报
回复
select * from 表 where b=max(b)
midnight2002 2004-04-19
  • 打赏
  • 举报
回复
刚才的有点问题,不好意思!!!

测试数据如下:
create table test(a char(1),b float,c int)

insert into test select 'w',0.1,1
union select 'w',0.3,2
union select 'w',0.2,3
union select 'w',0.6,4

select a,max(b),max(c) from test group by a

a
---- ----------------------------------------------------- -----------
w 0.59999999999999998 4

(所影响的行数为 1 行)





midnight2002 2004-04-19
  • 打赏
  • 举报
回复
select a,max(b),c from table_name group by a,c
iintsy 2004-04-19
  • 打赏
  • 举报
回复
SELECT a,b,c FROM 表名 where b = (SELECT MAX(b) from 表名)
pbsql 2004-04-19
  • 打赏
  • 举报
回复
select t.a,t.b,t.c
from t,(select a,max(b) from t group by a) tem
where t.a=tem.a and t.b=tem.b
zjcxc 元老 2004-04-19
  • 打赏
  • 举报
回复
select a.*
from 表 a join(select a,c=max(c) from 表 group by a) b on a.a=b.a and a.c=b.c
ygghost 2004-04-19
  • 打赏
  • 举报
回复
select b from table where c=max(c)

select top 1 b from table order by c desc

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧