首页新闻找找看学习计划

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

0
悬赏园豆:20 [已解决问题] 解决于 2013-06-03 11:07

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

茶饭不思的主页 茶饭不思 | 初学一级 | 园豆:123
提问于:2013-05-30 21:39
< >
分享
最佳答案
0

去掉重复行 select distinct sno from sc

收获园豆:20
伏草惟存 | 小虾三级 |园豆:1420 | 2013-06-02 19:06

谢谢。已经解决了,我重新分组连表查!

茶饭不思 | 园豆:123 (初学一级) | 2013-06-03 11:07
其他回答(1)
0

一次性的查了这么多个数据库里的这么多表。。。如果出现重复数据可以用distinct,grounp by等关键字试试。

先找到那条重复的记录中对应的字段有可能出现在那张表中两次,这对这个字段,你应该distinct一下,我也大致猜想也想,

呵呵,,,

休小晓 | 园豆:21 (初学一级) | 2013-05-31 11:20

distinct这个关键字应该怎么用?

支持(0) 反对(0) 茶饭不思 | 园豆:123 (初学一级) | 2013-05-31 14:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册