DB2数据库必须掌握的常用语句(四)
创始人
2024-07-23 06:51:41
0

之前为大家介绍的DB2数据库必须掌握的常用语句(三)、DB2数据库必须掌握的常用语句(二)、DB2数据库必须掌握的常用语句(一),接下来为大家介绍更多的有关DB2数据库常用语句的知识。

1、由sales表中查找出订单金额大于"E0013业务员在1996/10/15这天所接每一张订单的金额"的所有订单

select *

from sales

where tot_amt>all

(select tot_amt

from sales

where sale_id='E0013'and order_date='1996/10/15')

order by tot_amt

2、计算'P0001'产品的平均销售单价

select avg(unit_price)

from sale_item

where prod_id='P0001'

3、找出公司女员工所接的定单

select sale_id,tot_amt

from sales

where sale_id in

(select sale_id from employee

where sex='F')

4、找出同一天进入公司服务的员工

select a.emp_no,a.emp_name,a.date_hired

from employee a

join employee b

on (a.emp_no!=b.emp_no and a.date_hired=b.date_hired)

order by a.date_hired

5、找出目前业绩超过232000元的员工编号和姓名

select emp_no,emp_name

from employee

where emp_no in

(select sale_id

from sales

group by sale_id

having sum(tot_amt)<232000)

6、查询出employee表中所有女职工的平均工资和住址在"上海市"的所有女职工的平均工资

select avg(salary)

from employee

where sex like 'f'

union

select avg(salary)

from employee

where sex like 'f' and addr like '上海市%'

7、在employee表中查询薪水超过员工平均薪水的员工信息

Select *

from employee

where salary>( select avg(salary)

from employee)

8、 找出目前销售业绩超过10000元的业务员编号及销售业绩,并按销售业绩从大到小排序

Select sale_id ,sum(tot_amt)

from sales

group by sale_id

having sum(tot_amt)>10000

order by sum(tot_amt) desc

9、 找出公司男业务员所接且订单金额超过2000元的订单号及订单金额

Select order_no,tot_amt

From sales ,employee

Where sale_id=emp_no and sex='M' and tot_amt>2000
 

10、 查询sales表中订单金额***的订单号及订单金额

Select order_no,tot_amt from sales

where tot_amt=(select max(tot_amt) from sales)

11、 查询在每张订单中订购金额超过4000元的客户名及其地址

Select cust_name,addr from customer a,sales b

where a.cust_id=b.cust_id and tot_amt>4000

12、 求出每位客户的总订购金额,显示出客户号及总订购金额,并按总订购金额降序排列

Select cust_id,sum(tot_amt) from sales

Group by cust_id

Order by sum(tot_amt) desc

【编辑推荐】

  1. DB2数据库优化超有用的几条基本策略
  2. 实例之Visual C#中实现DB2数据库的编程
  3. DB2数据库性能监控的具体步骤

 

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...
《非诚勿扰》红人闫凤娇被曝厕所... 【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...
2012年第四季度互联网状况报... [[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...