34,588
社区成员
发帖
与我相关
我的任务
分享
select a.*,b.*
from tb a,tb b
where a.[付款方式]=b.[付款方式] and a.[数量]>b.[数量]
这样更直观!呵呵/*---------------------------------
-- Author : htl258(Tony)
-- Date : 2009-08-31 15:09:32
-- Version: Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 (Intel X86)
Mar 29 2009 10:27:29
Copyright (c) 1988-2008 Microsoft Corporation
Enterprise Evaluation Edition on Windows NT 5.1 <X86> (Build 2600: Service Pack 2)
---------------------------------*/
--> 生成测试数据表:tb
If not object_id('[tb]') is null
Drop table [tb]
Go
Create table [tb]([名称] nvarchar(2),[付款方式] nvarchar(2),[数量] int,[出货类型] nvarchar(2),[出货数量] int,[出货重量] decimal(18,2))
Insert [tb]
Select N'惠普',N'预付',2,N'包裹',2,10.00 union all
Select N'惠普',N'预付',1,N'文件',1,3.00
Go
--Select * from [tb]
-->SQL查询如下:
select a.*,b.数量,b.出货类型,b.出货数量,b.出货重量
from tb a
join tb b
on a.[名称]=b.名称
and a.[付款方式]=b.[付款方式]
and a.[数量]>b.[数量]
/*
名称 付款方式 数量 出货类型 出货数量 出货重量 数量 出货类型 出货数量 出货重量
惠普 预付 2 包裹 2 10.00 1 文件 1 3.00
*/
TRY