为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

明月笑刀无情 2018-12-06 12:30:50
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
查看完整描述

3 回答

?
动漫人物

TA贡献1815条经验 获得超10个赞

去掉重复行 select distinct sno from sc

查看完整回答
反对 回复 2019-01-07
?
森栏

TA贡献1810条经验 获得超5个赞

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

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

呵呵,,,

查看完整回答
反对 回复 2019-01-07
?
哔哔one

TA贡献1854条经验 获得超8个赞

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

查看完整回答
反对 回复 2019-01-07
  • 3 回答
  • 0 关注
  • 610 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信