日期:2014-05-18 浏览次数:20479 次
select OrderID,SUM(Qty) AS[入库数量] From Order where OrderID like '%OrderNo-2388'
create table #Order ( ORderID nvarchar(100), Tcount int ) insert #Order select N'OrderNo-2388', 10000 union all select N'AAOrderNO-2388', 1000 --#1.建立一个临时表, 把Like中的OrderNo输进去 create table TableOrderID ( OrderID nvarchar(100) ) insert into TableOrderID select N'OrderNo-2388' --#2.查询 select b.OrderID, Tcount = SUM(Tcount) from #Order a inner join TableOrderID b on charindex(b.OrderID, a.OrderID) > 0 group by b.OrderID /* OrderID Tcount OrderNo-2388 11000 */
------解决方案--------------------
select max(OrderID),sum(Qty) AS[入库数量] from( select OrderID,Qty,1 as a From Order where OrderID like '%OrderNo-2388' ) tmp group by a