猿问

Sql Server SQL语句连表时出现重复数据?如何解决?求高手指教

select convert(varchar(20),po.[PurchasedOn],111) as PurchasedOn,cu.[CustomerCode],po.CustomerOrderNo,po.[OutTradeSN],

convert(varchar(20),co.[CreatedOn],111) as CreatedOn,shop.[ShopName],cate.[CategoryName],poi.PurchaseQuantity,(poi.PurchaseQuantity*poi.PurchasePrice) as PaymentForGoods,po.[Cn2CnFreightAmount],
((poi.PurchaseQuantity*poi.PurchasePrice)+po.[Cn2CnFreightAmount]) as TotalMoney,po.OutPaySN,po.[PurchaseByName],ca.[CompanyAlias],eo.[ExpressNo]
from [Erp].[trade].[PurchaseOrders] po
inner join [trade].[CustomerOrders] co on po.[CustomerOrderNo] = co.[OrderNo]
inner join [CRM].[Customers] cu on cu.[CustomerId]=co.[CustomerId]
inner join [trade].[PurchaseItems] poi on poi.[PurchaseOrderId]=po.PurchaseOrderId
inner join [goods].[Shops] shop on shop.[ShopId] = po.[ShopId]
inner join [goods].[Goods] good on good.[GoodsId] = poi.[GoodId]
inner join [goods].[Categories] cate on cate.[CategoryId] = good.[CategoryId]
inner join [trade].[ExpressOrders2PurchaseItems] eopi on eopi.[PurchaseItemId] = poi.[PurchaseItemId]
inner join [trade].[ExpressOrders] eo on eo.[ExpressOrderId] = eopi.[ExpressOrderId]
inner join [basic].[CompanyAlias] ca on ca.CompanyId = eo.ExpressCompanyId
where month(po.[PurchasedOn])=month(getdate()) and year(po.[PurchasedOn])=year(getdate())
order by po.[PurchasedOn] asc

明月笑刀无情
浏览 611回答 3
3回答

动漫人物

去掉重复行 select distinct sno from sc

森栏

一次性的查了这么多个数据库里的这么多表。。。如果出现重复数据可以用distinct,grounp by等关键字试试。 先找到那条重复的记录中对应的字段有可能出现在那张表中两次,这对这个字段,你应该distinct一下,我也大致猜想也想, 呵呵,,,

哔哔one

distinct这个关键字应该怎么用?
随时随地看视频慕课网APP

相关分类

SQL Server
我要回答