with dataTable as (SELECT ROW_NUMBER() OVER (ORDER BY DateTime asc) AS RowIndex,*, a.AcceptMoney - a.ActuallyMoney as Profits from ( select Convert(varchar, ProduceTime, 111) as DateTime , COUNT(orderid) as OrderNumber, SUM(PersonCount) as Number, SUM(Fare) as AcceptMoney, SUM(CustFare) as ActuallyMoney from B_Orders where PromulgatorCode = 1 and DATEDIFF(MONTH, ProduceTime, '2010-3-31 0:00:00') = 0 group by Convert(varchar, ProduceTime, 111)) a) select * from dataTable where 1=1 and RowIndex between @row1 and @row2
求这个Sql语句查询结果的总条数with dataTable as (SELECT ROW_NUMBER() OVER (ORDER BY DateTime asc) AS RowIndex,*, a.AcceptMoney - a.ActuallyMoney as Profits from ( select Convert(varchar, ProduceTime, 111) as DateTime , COUNT(orderid) as OrderNumber, SUM(PersonCount) as Number, SUM(Fare) as AcceptMoney, SUM(CustFare) as ActuallyMoney from B_Orders where PromulgatorCode = 1 and DATEDIFF(MONTH, ProduceTime, '2010-3-31 0:00:00') = 0 group by Convert(varchar, ProduceTime, 111)) a) select count(*) from dataTable where 1=1 and RowIndex between @row1 and @row2
update test set qty = qty - 1 where (location,sku,valid_date) in (select location,sku,min(valid_date) from test where location = 'chuwei' and item_code = '5678' group by location,sku) 以上语 ......