假设打分表为employee,打分为totalscore,歌手为checkedname
select a.checkedname,(a.sum1 - a.max1 - a.min1)/(count1-2) from
(select checkedname,sum(totalscore) sum1,count(*) count1,checkedname,max(totalscore) max1,min(totalscore) min1 from employee group by checkedname having count(*) > 2) a
select a.checkedname,(a.sum1 - a.max1 - a.min1)/(count1-2) from
(select checkedname,sum(totalscore) sum1,count(*) count1,checkedname,max(totalscore) max1,min(totalscore) min1 from employee group by checkedname having count(*) > 2) a
解决方案 »
- Oracle安装IP地址问题
- db_block_checking和db_block_checksum区别
- ORACLE存储过程的问题
- 请问关于阶段性时间归总的sql语句
- 求各位大哥给个算法(数据结构与算法)
- 执行下面的procedure时提示我“ORA-01031:权限不足”,应该如何改写下面的procedure呢?
- 数据字典是什么?起什么作用啊?能给一个样例看看吗?
- 急问:OMS问题及数据库迁移
- IMP的问题,数据量太大了,导入时又慢,而且会报错!~高分求助
- 关于sqlload的奇怪现象,HELP!!!
- 如何用sql插入data类型的变量啊!
- SQL server和ORACAL的性能谁好些?????
from table
where 歌手='歌手名'
/
select (sum(totalscore)-max(totalscore)-min(totalscore))/(count(*)-2),checkedname from employee group by checkedname having count(*) > 2
(
totalscore number,
checkedname varchar2(10)
);insert into employee values (100,'a');
insert into employee values (20,'a');
insert into employee values (10,'a');
insert into employee values (100,'a');
commit;select a.checkedname,(a.sum1 - a.max1 - a.min1)/(count1-2) from
(select checkedname,sum(totalscore) sum1,count(*) count1,
max(totalscore) max1,min(totalscore) min1 from
employee group by checkedname having count(*) > 2) aa 60
e from employee group by checkedname having count(*) > 2
15:25:05 2 ;(SUM(TOTALSCORE)-MAX(TOTALSCORE)-MIN(TOTALSCORE))/(COUNT(*)-2) CHECKEDNAM
-------------------------------------------------------------- ----------
60 a
jlandzpa,平均分就是60吧
jlandzpa真仔细啊
ATCG(ATCG) :题就这么出的。
以上解答都不对,只是去掉了一个最高分和一个最低分。
各位继续!
有些不明白,你所指的不能有子查询是指WHERE后的SELECT ,还是FROM 后的SELECT ,还是字段列表中的SELECT ,还是都包括?
SQL> select * from employee;TOTALSCORE CHECKEDNAM
---------- ----------
100 a
20 a
10 a
100 a
100 a
10 a
20 a
30 a已选择8行。
SQL> SELECT SUM(TOTALSCORE)/COUNT(*) FROM (SELECT * FROM EMPLOYEE WHERE TOTALSCORE <>(SELECT MAX(TOT
ALSCORE) FROM EMPLOYEE) AND TOTALSCORE <>(SELECT MIN(TOTALSCORE) FROM EMPLOYEE));SUM(TOTALSCORE)/COUNT(*)
------------------------
23.333333这样正确了吧
bzszp(SongZip) :呵呵,你的解答已经有子查询了,CUT掉!
而且都不能有select子句,那够难
19:55:24 jlanzpa817>insert into employee values (20,'a');已创建 1 行。已用时间: 00: 00: 00.10
19:55:24 jlanzpa817>insert into employee values (10,'a');已创建 1 行。已用时间: 00: 00: 00.10
19:55:24 jlanzpa817>insert into employee values (100,'a');已创建 1 行。已用时间: 00: 00: 00.40
19:55:24 jlanzpa817>commit;提交完成。已用时间: 00: 00: 00.50
19:55:43 jlanzpa817>select avg(totalscore)
19:56:19 2 from
19:56:19 3 (select checkedname,totalscore from employee) a,
19:56:19 4 (select max(totalscore) score from employee
19:56:19 5 union
19:56:19 6 select min(totalscore) score from employee) b
19:56:19 7 where a.totalscore = b.score(+) and b.score is null;AVG(TOTALSCORE)
---------------
20已用时间: 00: 00: 00.20
19:56:19 jlanzpa817>
to Leehunter(理性猎人) :
有些不明白,你所指的不能有子查询是指WHERE后的SELECT ,还是FROM 后的SELECT ,还是字段列表中的SELECT ,还是都包括?
Leehunter(理性猎人) ( ) 信誉:100 2002-08-14 17:17:00 得分:0
CHENGXB(大山) :都不能有子查询。
bzszp(SongZip) :呵呵,你的解答已经有子查询了,CUT掉!
这两句一写,估计难倒99%以上的人了
至少,我是想破脑袋了!
今晚还是别睡了吧,睡也睡不舒服。
from employee a,employee b,employee c
where a.checkedname = b.checkedname and
a.checkedname = c.checkedname and
a.totalscore > b.totalscore and
a.totalscore < b.totalscore
group by a.checkedname,a.totalscore 这里没有SQL的执行环境,不知道是不是有错。
你这个SQL 不会有任何结果,因为
select *
from employee a,employee b,employee c
where a.checkedname = b.checkedname and
a.checkedname = c.checkedname and
a.totalscore > b.totalscore and
a.totalscore < b.totalscore
的结果为空,关联的条件自相矛盾!
还有表结构、有几张表,表之间的关系,
以及提供一部分数据。我想如果客观上
有解,就应该能做出来。
晚上有空帮你想想,千万别想破
脑袋啊!,脑袋破了,什么都没了。比
我这个快失业的人还要惨了。
from employee a,employee b,employee c
where a.checkedname = b.checkedname and
a.checkedname = c.checkedname and
a.totalscore > b.totalscore and
a.totalscore < c.totalscore
group by a.checkedname
09:11:25 2 from employee a,employee b,employee c
09:11:25 3 where a.checkedname = b.checkedname and
09:11:25 4 a.checkedname = c.checkedname and
09:11:25 5 a.totalscore > b.totalscore and
09:11:25 6 a.totalscore < c.totalscore
09:11:25 7 group by a.checkedname
09:11:25 8 ;CHECKEDNAM AVG(A.TOTALSCORE)
---------- -----------------
a 20已用时间: 00: 00: 00.20
create table tab_score (score number);
wclarity(水澈) :算了一下,不对
select (sum(score*count(*))-max(score*count(*))-min(score*count(*)))/(sum(count(*))-max(score*count(*))/max(score)-min(score*count(*))/min(score))
from tab_score group by score
开始以为正确了,后来才发现是特例。
不过根据大家的一点想法提示,写出来一个很菜的结果,大家看看可以优化不
select avg(distinct(a.totalscore)),a.checkedname from employee a,employee b,employee c
where a.checkedname = b. checkedname and a.totalscore<b.totalscore and
a.checkedname = c.checkedname and a.totalscore>c.totalscore group by a.checkedname having count(*) > 2
如果中间没有重复值就正确了。
select avg(distinct(dbms_rowid.ROWID_ROW_NUMBER(a.rowid)*100+a.totalscore))-avg(distinct(dbms_rowid.ROWID_ROW_NUMBER(a.rowid)))*100 avg1,
a.checkedname from employee a,employee b,employee c
where a.checkedname = b.checkedname and a.totalscore<b.totalscore and
a.checkedname = c.checkedname and a.totalscore>c.totalscore group by a.checkedname having count(*) > 2
select avg(distinct(dbms_rowid.ROWID_ROW_NUMBER(a.rowid)*100+a.totalscore))-avg(distinct(dbms_rowid.ROWID_ROW_NUMBER(a.rowid)))*100 avg1,
a.checkedname from employee a,employee b,employee c
where a.checkedname = b.checkedname and a.totalscore<b.totalscore and
a.checkedname = c.checkedname and a.totalscore>c.totalscore and a.totalscore between 0 and 100 group by a.checkedname having count(*) > 2
有没有更简便的?
select avg(distinct(dbms_rowid.ROWID_ROW_NUMBER(a.rowid)*100+a.totalscore))-avg(distinct(dbms_rowid.ROWID_ROW_NUMBER(a.rowid))*100) avg1,
a.checkedname from employee a,employee b,employee c
where a.checkedname = b.checkedname and a.totalscore<b.totalscore and
a.checkedname = c.checkedname and a.totalscore>c.totalscore and a.totalscore between 0 and 100 group by a.checkedname having count(*) > 2
---------- ----------
20 a
30 a
10 a
100 a
100 a
100 b
20 b
10 b
100 b已选择9行。已用时间: 00: 00: 00.20
17:45:17 jlanzpa817>select avg(distinct(dbms_rowid.ROWID_ROW_NUMBER(a.rowid)*100+a.totalscore))
17:45:25 2 -avg(distinct(dbms_rowid.ROWID_ROW_NUMBER(a.rowid)))*100 avg1,a.checkedname
17:45:25 3 from employee a,employee b,employee c
17:45:25 4 where a.checkedname = b.checkedname and a.totalscore<b.totalscore and
17:45:25 5 a.checkedname = c.checkedname and a.totalscore>c.totalscore and
17:45:25 6 a.totalscore between 0 and 100 group by a.checkedname having count(*) > 2; AVG1 CHECKEDNAM
---------- ----------
25 a已用时间: 00: 00: 00.20b的没有出来?
select avg(distinct(dbms_rowid.ROWID_ROW_NUMBER(a.rowid)*100+a.totalscore))-avg(distinct(dbms_rowid.ROWID_ROW_NUMBER(a.rowid))*100) avg1,
a.checkedname from employee a,employee b,employee c
where a.checkedname = b.checkedname and a.totalscore<b.totalscore and
a.checkedname = c.checkedname and a.totalscore>c.totalscore and a.totalscore between 0 and 100 group by a.checkedname
小弟又学了一招,^_^
to xzou(亡狼补齿) :恭喜你,亡狼补齿同学,你可以从ORACLE大学毕业了!!! ORACLE大学校长