易截截图软件、单文件、免安装、纯绿色、仅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_name
--11、用存在量词查找没有订货记录的客户名称
select cust_name
from customer a
where not exists
(select *
from sales b
where a.


相关文档:

SQL SERVER使用链接服务器

1、在另一台机器上建立独立的数据库服务器,作为链接目标
2、本地数据库服务器上添加“链接服务器”:
名字:随便取一个名字
服务器类型:选择数据源:Microsoft OLE DB Provider for SQL Server
数据源:写别名(在客户端网络实用工具中设置)
选中RPC和RPC输出 ......

SQL 2005 存储过程分页

create PROCEDURE [dbo].[P_PageTest]
    @SQL Nvarchar(max),  --SQL语句不包括排序
    @CurPage int,    --当前页
    @PageRows int,    --页面尺寸
 @Order Nvarchar(20),  --排序字段
 @OrderType Nvarchar( ......

sql 查询

有以下二张表:
政党表:政党ID,政党名称
议员表:议员ID,议员名称,政党ID
要求查询所有的政党信息,包含:政党名称,议员人数,并按议员人数的降序排列(不可以用子查询)。
正解:
SELECT a.name,
  COUNT(b.id) AS counts
  from zhen a
left join
  yi b
on a.id=b.zhenid
GROUP ......

SQL Server补丁版本的检查

SQL Server的补丁版本检查不如Windows 补丁版本检查直接,一个系统管理员,如果不了解SQL Server版本对应的补丁号,可能也会遇到一点麻烦,因此在这说明一下,通过这样的办法判别机器是安全的办法,不会对系统产生任何影响。
 
1、用Isql或者SQL查询分析器登录到SQL Server,如果是用Isql,请在cmd窗口输入isql -U sa,然 ......

MySQL 严格模式 sql_mode

虽然说我们尽量在写程序的时候控制插入到数据库的数据,而不要用数据库去判断数据的对错,但是有时候为了方便还是需要数据库自身的容错能力来帮助我们达到目的的。举例说明:
创建如下数据表
CREATE TABLE `book` (
  `id` int(11) default NULL,
  `num` int(11) unsigned default NULL
) ENGINE=InnoDB DE ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号