大家帮忙,求一个sql`~

hudingchen 2007-10-27 01:33:17
sql1:"select..." 它返回的结果如下:
id count
1 10
2 20
3 30
4 40
我现在想对count求最大值,然后对应每个ID,对sql1查询1次,怎么写??得到如下结果:
id count max
1 10 40
2 20 40
3 30 40
4 40 40
...全文
87 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanling1984 2007-10-29
  • 打赏
  • 举报
回复

select distinct dd.d1,dd.d2,max(t.count) over()
from demo t
inner join ( select d.id d1,sum(d.count) d2
from demo d group by d.id) dd on dd.d1=t.id
order by dd.d1
karlpan01 2007-10-27
  • 打赏
  • 举报
回复
select id,count,max(count) over() max from table
mantisXF 2007-10-27
  • 打赏
  • 举报
回复


select zz.*,
max(count) over() as "max_count"
from (
select tt.id,
count(*) as "count"
from tablename tt
group by tt.id
)zz;

Croatia 2007-10-27
  • 打赏
  • 举报
回复
select id,count,max(count) over() max from table
JadoNet 2007-10-27
  • 打赏
  • 举报
回复
select a.* ,b.* from
table1 a,
(select max(t.count) from table1 t) b

忘记给表取别名了
JadoNet 2007-10-27
  • 打赏
  • 举报
回复
select a.* ,b.* from
table1 a,
(select max(t.count) from table1) b

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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