首页 > 代码库 > distinct与order by
distinct与order by
不知为啥,当我得查询中出现distinct时,order by 中必须包含要查询的列,否则报错。
SELECT DISTINCT a.DetailId, a.OrderId, a.ProductId, pi2.BarCode, pi1.ProductName, pi1.productCode, pi1.spec, a.UnitId, ui.UnitName, SNUM(a.DetailId) as Quantity, a.Discount, a.UnitPrice, a.TaxRate, a.ProductMoney, a.TaxMoney, a.PayableMoney, a.IsGiveAway, a.DetailId AS ColGuid, a.ParentGuid, a.DetailId AS OrderDetailId, a.OrderId AS RelevanceOrder, a.Memo, pi2.SalePrice AS InitUnitPrice, a.SEQ, ---必须包含这个,否则报错 a.Quantity - SNUM(a.DetailId) AS OutQuantityFROM SaleOrderDetail aLEFT JOIN ProductInfo pi1 ON a.ProductId = pi1.ProductIdLEFT JOIN ProductPrice pi2 ON a.ProductId = pi2.ProductIdAND pi2.unitid = a.unitidLEFT JOIN UnitInfo ui ON a.UnitId = ui.UnitIdWHERE a.DetailId IN (SELECT COLUMN_VALUE FROM TABLE(SPLITSTR(IDS, ‘,‘)))ORDER BY a.SEQ ASC
distinct与order by
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。