关于group by 的一个SQL题目
来源:互联网 发布:阿里云风云令更换手机 编辑:程序博客网 时间:2024/06/10 04:45
获得部门最高工资比别的部门平均工资还低的部门及平均公司信息。
表如下: employee table
+----+--------+--------+------+
| id | name | salary | dept |
+----+--------+--------+------+
| 1 | test1 | 99 | dep1 |
| 2 | test2 | 89 | dep1 |
| 3 | test3 | 73 | dep1 |
| 4 | test4 | 87 | dep1 |
| 5 | test5 | 85 | dep1 |
| 6 | test6 | 84 | dep2 |
| 7 | test7 | 82 | dep2 |
| 8 | test8 | 80 | dep2 |
| 9 | test9 | 86 | dep2 |
| 10 | test10 | 79 | dep2 |
| 11 | test11 | 83 | dep3 |
| 12 | test12 | 80 | dep3 |
+----+--------+--------+------+
12 rows in set (0.00 sec)
有两个sql解决方案:
1,select a.*,b.* from
(select dept,max(salary) maxsalary from test group by dept) a,
(select dept,avg(salary) avgsalary from test group by dept) b
where a.maxsalary<b.avgsalary
2,select dept, max(salary) from employee group by dept having max(salary) in (select max(salary) from employee group by dept having max(salary) < some (select avg(salary) from employee group by dept))
第二题, 写一个SQL语句用来检查某个字段中是否存在重复的值,并输出重复的值和次数。
select dept, count(dept) from test.employee group by dept
第三题 横表变竖表
第四题,oracle如何更新一个表的sequence
alter seq increment by 1000;
select seq.nextval from seq;
alter seq increment by 1;
第五题, 如果更新一个表中的时间字段
update employee set start_date = SYSDATE - 5 where id = 1234;
or update employee set start_date = to_date('2003-06-13 15:18','YYYY-MM-DD hh:mm');
- 关于group by 的一个SQL题目
- 关于having,group by 的Sql 语句
- 关于having,group by 的Sql 语句
- sql的group by
- SQL的 Group By
- SQL的GROUP by
- sql server 之group by的用法(关于统计)
- 浅谈关于SQL数据库中Group By的用法
- 一道SQL语句面试题,关于group by的
- sql中关于分组(group by)的理解
- Sql group by 的使用方法
- SQL GROUP BY的用法
- SQL group by的困惑
- SQL group by的困惑
- SQL GROUP BY的用法
- sql,group by的使用
- SQL Group by的使用
- SQL的GROUP BY详解
- 线程函数参数(LPVOID Param)
- Weblogic应用程序部署指南
- Python建立Web文件服务
- UBOOT添加命令的执行流程
- u-boot命令介绍及烧写程序实例
- 关于group by 的一个SQL题目
- ArcEngine双向联动鹰眼图源码
- centos安装ntp服务器
- Linux系统下C++开发工具
- Unix 学习笔记
- kjava,jad描述顺序
- vc++ 在程序中运行另一个程序的方法
- 转贴 MAF Step by Step
- Mysql 日志文件介绍