日期:2014-05-17 浏览次数:20452 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-02-22 16:42:00
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64)
-- Jun 17 2011 00:54:03
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1, v.721)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([单号] int,[日期] datetime,[名称] varchar(5),[数量] int,[金额] int)
insert [huang]
select 13020101,'2013-2-1','电脑',20,66000 union all
select 13020101,'2013-2-1','赠品A',10,600 union all
select 13020202,'2013-2-2','手机',20,66000 union all
select 13020202,'2013-2-2','赠品B',5,300 union all
select 13020303,'2013-2-3','手机',3,9900 union all
select 13020404,'2013-2-4','电脑',2,6600
--------------开始查询--------------------------
SELECT b.单号 ,
b.日期 ,
a.名称 ,
b.数量 ,
b.金额
FROM ( SELECT *
FROM huang
WHERE 名称 NOT LIKE '赠品%'