热门关键字:  ubuntu  分区  Fedora  linux系统进程  函数

学习DB2数据库必须掌握的五十四条常用语句 (1)

来源: 作者: 时间:2008-05-09 Tag: 点击:

8、查找在1997年中有销售记录的客户编号、名称和订单总额

select a.cust_id,cust_name,sum(tot_amt) totprice

from customer a,sales b

where a.cust_id=b.cust_id and convert(char(4),order_date,120)='1997'

group by a.cust_id,cust_name

9、查找一次销售最大的销售记录

select order_no,cust_id,sale_id,tot_amt

from sales

where tot_amt=

(select max(tot_amt)

from sales)

10、查找至少有3次销售的业务员名单和销售日期

select emp_name,order_date

from employee a,sales b

where emp_no=sale_id and a.emp_no in

(select sale_id

from sales

group by sale_id

having count(*)>=3)

order by emp_name

11、用存在量词查找没有订货记录的客户名称

select cust_name

from customer a

where not exists

(select *

from sales b

where a.cust_id=b.cust_id)

 

12、使用左外连接查找每个客户的客户编号、名称、订货日期、订单金额订货日期不要显示时间,日期格式为yyyy-mm-dd按客户编号排序,同一客户再按订单降序排序输出

select a.cust_id,cust_name,convert(char(10),order_date,120),tot_amt

from customer a left outer join sales b on a.cust_id=b.cust_id

order by a.cust_id,tot_amt desc




相关文章:
db2日期操作函数
SQL 语法参考手册
谈谈IBM DB2的数据库备份与恢复
对 DB2 V9 中 XML 类型的编码处理(dW)
构建DB2 Cube View元数据桥
DB2存储过程开发最佳实践
DB2中使用所有内存
DB2与SQL Server2000间SQL数据复制
用户和组帐户与DB2 UDB的交互
DB2 9数据库优点及缺点详细分析
DB2中实现Oracle的相关功能
将Siebel 7电子商务应用程序从DB2 UDB V8 迁移到D
解析:DB2 无限活动日志策略的实用技巧
DB2 9数据服务器发展的3个阶段
为DB2数据库添加验证约束
DB2数据库创建存储过程时遇到的错误
DB2 9数据库性能理解的二十大误区
DB2中的终极SQL性能调节技术
DB2数据库应用系统性能优化深入探究
提高DB2 Web程序性能5条规则
详解安装DB2 9数据库管理软件的4种方式
DB2 9.5的数据库内存保护技术
解决DB2中出现的SQL1032N错误现象
创建克隆文件
DB2数据库优化的几条策略
如何解决DB2中出现的SQL1032N错误现象
解决DB2数据库代码页不兼容的问题
DB2创建存储过程时遇到的错误
教你提高商业智能环境中的DB2查询性能
DB2 9.5的数据库内存保护