假设有2个表,users和groups,
table users table groups
------------------ -------------------------
name point name group
(名字) (分数) (名字) (部门)
1)用一句sql找出分数最高者所在的部门
2)用一句sql找出平局分数最高的部门另:假设一个表里有销售量(count)和时间2个字段(date),时间假如说是20040101-20060601
如何按月查询每月的销售量?
table users table groups
------------------ -------------------------
name point name group
(名字) (分数) (名字) (部门)
1)用一句sql找出分数最高者所在的部门
2)用一句sql找出平局分数最高的部门另:假设一个表里有销售量(count)和时间2个字段(date),时间假如说是20040101-20060601
如何按月查询每月的销售量?
解决方案 »
- oracle查询某月所有日期的sql
- win7安装oracle11gr2client(都是64位的)问题反馈,求解决
- 查询语句检索问题
- 急,打开Enterprise Manager console和Net configuration assistant报同样的错误(oran9.dll)
- ORACLE中视图如何从不同的数据库表中取数据
- ORACLE用PLSQL导入表,会导入错误的系统表
- win2003安装oracle8.1.7问题
- OraQuery小問題請教:如何獲得一個字段的已知值在該字段對應的序號?
- oracle性能在删除记录后大大降低,求助大家了
- 求救,有关嵌套表问题
- 如何将Oracle中的from dual转为SQL语句
- 向各位请教:两台windows如何建立建立数据库链路?
from groups a,users b
where a.name = b.name
and b.point = (select max(point) from users)
2):with aaa as (select b.group,max(avg(a.point))
from users a,groups b
where a.name = b.name
group by b.group)
select bbb.group
from group bbb,aaa
where aaa.group = bbb.group
3):select sum(nvl(count,0)) from table
group by date
1)a b 都是什么?
写成这样行吗?
select group from groups where users.name=groups.name and point=max(point);
2)with aaa as什么意思?
aaa bbb是什么?
注:表名就叫users 和 groups
表users 有2个字段name point
表groups有2个字段name group
3)能不能解释一下sum(nvl(count,0))这个函数的意思?小弟新手,希望多多指点,因为急着用,来不及看书了,一定会补上,希望先帮忙解答一下!
你的写法不对
2)with aaa as ...你可以理解为创建了一个临时表,表名aaa
bbb也是表的别名
3)nvl(count,0)是如果count为空则赋值为0,sum是求和函数
因为date的格式为yyyymmdd
如果是yyyymm,是按月查
如果是yyyy是按年查
1)a b 都是什么?
写成这样行吗?
select group from groups where users.name=groups.name and point=max(point);不能这样写,users.name和groups.name在多表引用中只能用别名,所以一定要起个别名,用a.name和b.name来限制
from groups a,users b
where a.name = b.name
and b.point = (select max(point) from users)
2):with aaa as (select b.group,max(avg(a.point))
from users a,groups b
where a.name = b.name
group by b.group)
select bbb.group
from group bbb,aaa
where aaa.group = bbb.group
3):select sum(nvl(count,0)) from table
group by substr(to_char(date,'yyyymmdd'),0,6)