中易网

oracle查询最小值所在行数据

答案:2  悬赏:20  
解决时间 2021-04-27 11:02
SQL> select tablea.车牌, tablea.数值, tablea.序号, tableb.数值, tableb.序号, min(tablea.数值-tableb.数值)as T from tablea, tableb where tablea.车牌=tableb.车牌 and tablea.序号=1 and tableb.序号=1 and tablea.数值-tableb.数值>0 group by tablea.车牌, tablea.数值, tablea.序号, tableb.数值, tableb.序号;

a、700对应的只需要T最小的一列,即1所在的列
我的处理办法1:
SQL> select tablea.车牌, tablea.数值, tablea.序号, min(tablea.数值-tableb.数值)as T from tablea, tableb where tablea.车牌=tableb.车牌 and tablea.序号=1 and tableb.序号=1 and tablea.数值-tableb.数值>0 group by tablea.车牌, tablea.数值, tablea.序号;

这样子就不无法得到另外两列数据,除非另外插入。
办法2:
SQL> select tablea.车牌, tablea.数值, tablea.序号, tableb.数值, tableb.序号, min(tablea.数值-tableb.数值) over (partition by tablea.车牌,tablea.数值) from tablea, tableb where tablea.车牌=tableb.车牌 and tablea.序号=1 and tableb.序号=1 and tablea.数值-tableb.数值>0;

这样的话,不知道怎么只显示对的那一行。

前面说的太复杂了,其实就是子查询时遇到问题。从下图第一个结果中查询,条件是m=1,不要建临时表、视图的方法,应该怎么处理,写了几句都不对。不知道为什么












最佳答案
对这类没悬赏又长的题不太喜欢回答,不过为了采纳率,还是告诉你办法吧。
把你写的东西看成是一个table,再连接要获取字段的对应table就可以了,是不 是很简单?
select * from (
select tablea.车牌, tablea.数值, tablea.序号, min(tablea.数值-tableb.数值)as T from tablea, tableb where tablea.车牌=tableb.车牌 and tablea.序号=1 and tableb.序号=1 and tablea.数值-tableb.数值>0 group by tablea.车牌, tablea.数值, tablea.序号) AS A , tablea AS B, tableb AS C
where A车牌=B.车牌 and A.车牌=C.车牌
AND A.序号=B.序号 AND........他们之间的关系,自己会写吧?
全部回答
select max(case when d.cnt = d.max_cnt then d.crown else null end) as max_crown,d.max_cnt, max(case when d.cnt = d.min_cnt then d.crown else null end) as min_crown, d.min_cnt from ( select s.crown, s.cnt, max(s.cnt) over () as max_cnt, min(s.cnt) over () as min_cnt from ( select s0.crown, count(s0.year) as cnt from history s0 group by s0.crown ) s ) d group by d.max_cnt, d.min_cnt; 结果中, max_crown为夺冠最多的球队名称, max_cnt为球队最多的夺冠次数; min__crown为夺冠最少的球队名称, min_cnt为球队最少夺冠次数.
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
高分球乔丹补丁
福州到成都要经过那些地方
从石家庄长途客运站到杭州坐高客多长时间及报
准周期信号的周期截取
谁能告诉我金毛狗怎么养法
庄桥地址在什么地方,想过去办事
给宝宝冲奶粉的6大误区 宝妈们都知道吗
DOTA输入什么指令能变成阴霸模式
某些可溶性金属氧化物加水形成碱
发票二维码盖上发票代码一个数字能验证吗?
怡江苑东门(人行门)在什么地方啊,我要过去处
为什么我的手机QQ开了震动刚几天会震动,可是
微信小视频制作
南京晓庄学院方山校区-理科组团教学楼C在什么
怎样才能在电脑上投小说稿
推荐资讯
赛尔号的浮空苗去哪抓
用20牛的水平推力推重50牛的箱子 在水平地面
as it is reported 还是 as is reported
湖里区厦门如意旅馆(塘边社店)这个地址怎么能
三十六张杠、七艘船装。装单不装双。请问怎麽
虞姬的家乡在哪里?
人为什么一定会生病?
怎样把电脑上的图发送到手机上???
免费的QQ空间怎么弄
建设广场A座在哪里啊,我有事要去这个地方
为什么我在网站上的图片保存不了,而且完了之
黑瀑布生发堂佛山.顺德专卖店我想知道这个在
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?