易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL 语句练习


–1、查找员工的编号、姓名、部门和出生日期,如果出生日期为空值,显示日期不详,并按部门排序输出,日期格式为yyyy-mm-dd。
select emp_no,emp_name,dept,isnull(convert(char(10),birthday,120),’日期不详’) birthday
from employee
order by dept
–2、查找与喻自强在同一个单位的员工姓名、性别、部门和职称
select emp_no,emp_name,dept,title
from employee
where emp_name<>’喻自强’ and dept in
(select dept from employee
where emp_name=’喻自强’)
–3、按部门进行汇总,统计每个部门的总工资
select dept,sum(salary)
from employee
group by dept
–4、查找商品名称为14寸显示器商品的销售情况,显示该商品的编号、销售数量、单价和金额
select a.prod_id,qty,unit_price,unit_price*qty totprice
from sale_item a,product b
where a.prod_id=b.prod_id and prod_name=’14寸显示器’
–5、在销售明细表中按产品编号进行汇总,统计每种产品的销售数量和金额
select prod_id,sum(qty) totqty,sum(qty*unit_price) totprice
from sale_item
group by prod_id
–6、使用convert函数按客户编号统计每个客户1996年的订单总金额
select cust_id,sum(tot_amt) totprice
from sales
where convert(char(4),order_date,120)=’1996′
group by cust_id
–7、查找有销售记录的客户编号、名称和订单总额
select a.cust_id,cust_name,sum(tot_amt) totprice
from customer a,sales b
where a.cust_id=b.cust_id
group by a.cust_id,cust_name
–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_na


相关文档:

tempdb对SQL Server数据库性能有何影响

tempdb对SQL Server数据库性能有何影响
 
本文关键词:SQL Server 网络
相反如果访问很频繁,loading就会加重,tempdb的性能就会对整个DB产生重要的影响.优化tempdb的性能变的很重要的,尤其对于大型数据库.如果使用临时表储存大量的数据且频繁访问,考虑添加index以增加查询效率.
   1.SQL Server系统数据库介 ......

SQL逻辑查询处理顺序

SQL不同于其他编程语言的最明显特征是处理代码的顺序。在大多数据库语言中,代码按编码顺序被处理。但在SQL语句中,第一个被处理的子句式from,而不是第一出现的SELECT。SQL查询处理的步骤序号:
      
view source
< id="highlighter_299531_clipboard" title="copy to clipboard" clas ......

SQL Server JDBC 驱动封装

1、建立一个jdbc.jsp 文件:
2、将下面相应的代码复制到jdbc.jsp中
3、编写要连接到数据库的jsp文件时,只需将jdbc.jsp文件包含到该jsp文件中就行了
方法:添加<%@  include file="jdbc.jsp">到jsp文件中即可
//sql server2005:
<%@ page language="java" import ="java.util.*"%>
 
<%
& ......

SQL 中的命令大全

--语 句 功 能 
--数据操作 
SELECT --从数据库表中检索数据行和列 
INSERT --向数据库表添加新数据行 
DELETE --从数据库表中删除数据行 
UPDATE --更新数据库表中的数据 
--数据定义 
CREATE TABLE --创建一个数据库表 
DROP TABLE --从数据库中删除表 
......

sql中 in 、not in 、exists、not exists 用法和差别


exists (sql 返回结果集为真) 
not exists (sql 不返回结果集为真) 
如下: 
表A 
ID NAME 
1    A1 
2    A2 
3  A3 
表B 
ID AID NAME 
1    1 B1 
2  & ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号