图里面打错了个字,就是"果"应该是"何",这是打字的时候词组选择性问题.不好意思.希望有人能帮帮忙.

解决方案 »

  1.   

    select orderparentid, min(ordermoney) as ordermoney
      from (select orderparentid, sum(ordermondy) as ordermoney from tb
        group by orderparentid) t
      order by orderparentid
      

  2.   


    select orderparentid, min(ordermoney) as ordermoney
       from (select orderparentid, sum(ordermondy) as ordermoney from tb
          group by orderparentid) t
          order by orderparentid
      

  3.   

    我这里测试数据,就两列create table Lnorder(OrderParentId int,OrderMoney int)
    insert Lnorder 
    select 100,500 union all
    select 101,500 union all
    select 101,500 union all
    select 101,500 union all
    select 100,500 union all
    select 100,500 union all
    select 100,500 union all
    select 100,500 union all
    select 103,500 union all
    select 103,500 union all
    select 0,0 goselect 
    case when 
    (select sum(OrderMoney) from Lnorder where OrderParentId = 101)
     > 
    (select sum(OrderMoney) from Lnorder where OrderParentId = 103)
    then 
    (select sum(OrderMoney) from Lnorder where OrderParentId = 103)
    else
    (select sum(OrderMoney) from Lnorder where OrderParentId = 101)
    end            
    ----------- 
    1000(所影响的行数为 1 行)
      

  4.   

    select orderparentid, min(ordermoney) as ordermoney
      from (select orderparentid, sum(ordermondy) as ordermoney from tb
        group by orderparentid) t
      order by orderparentid
      

  5.   

    select orderparentid, min(ordermoney) as ordermoney
      from (select orderparentid, sum(ordermondy) as ordermoney from tb where orderparentid in('101','103')    group by orderparentid) t
      order by orderparentid
      

  6.   


    create table Lnorder(OrderParentId int,OrderMoney int)
    insert Lnorder 
    select 100,500 union all
    select 101,500 union all
    select 101,500 union all
    select 101,500 union all
    select 100,500 union all
    select 100,500 union all
    select 100,500 union all
    select 100,500 union all
    select 103,500 union all
    select 103,500 union all
    select 0,0  
    if (select sum(OrderMoney) from Lnorder where OrderParentId = 101)>(select sum(OrderMoney) from Lnorder where OrderParentId = 103)
    select sum(OrderMoney) from Lnorder where OrderParentId = 103
    else
    select sum(OrderMoney) from Lnorder where OrderParentId = 101/*
    1000
    */
      

  7.   

    SELECT TOP 1 * FROM (
    SELECT ORDERPARENTID ,SUM(ORDERMONEY) 'TOTAL' FROM LNORDER WHERE ORDERPARENTID IN (101,103)
    GROUP BY ORDERPARENTID 
    )
    ORDER BY TOTAL ASC
      

  8.   

    declare @Lnorder table(OrderParentId int,OrderMoney int)
    insert @Lnorder 
    select 100,500 union all
    select 101,500 union all
    select 101,500 union all
    select 101,500 union all
    select 100,500 union all
    select 100,500 union all
    select 100,500 union all
    select 100,500 union all
    select 103,500 union all
    select 103,500 union all
    select 0,0 select top 1 OrderParentId,sum(OrderMoney) OrderMoney from @Lnorder where OrderParentId in(101,103)
     group by OrderParentId order by OrderMoney asc
      

  9.   

    declare @Lnorder table(OrderParentId int,OrderMoney int)
    insert @Lnorder 
    select 100,500 union all
    select 101,500 union all
    select 101,500 union all
    select 101,500 union all
    select 100,500 union all
    select 100,500 union all
    select 100,500 union all
    select 100,500 union all
    select 103,500 union all
    select 103,500 union all
    select 0,0 select top 1 OrderParentId,sum(OrderMoney) OrderMoney from @Lnorder where OrderParentId in(101,103)
     group by OrderParentId order by OrderMoney asc
    OrderParentId OrderMoney
    ------------- -----------
    103           1000(1 行受影响)
      

  10.   

    declare @Lnorder table(OrderParentId int,OrderMoney int)
    insert @Lnorder 
    select 100,500 union all
    select 101,500 union all
    select 101,500 union all
    select 101,500 union all
    select 100,500 union all
    select 100,500 union all
    select 100,500 union all
    select 100,500 union all
    select 103,500 union all
    select 103,500 union all
    select 0,0 
    --(1)
    ;with hgo as
    (
     select OrderParentId,sum(OrderMoney) OrderMoney from @Lnorder where OrderParentId in(101,103)
     group by OrderParentId
    )
    select min(OrderMoney) OrderMoney from hgo
    --(2)
    select top 1 OrderParentId,sum(OrderMoney) OrderMoney from @Lnorder where OrderParentId in(101,103)
     group by OrderParentId order by OrderMoney asc
      

  11.   


    select orderparentid, min(ordermoney) as ordermoney
      from (select orderparentid, sum(ordermondy) as ordermoney from tb
        group by orderparentid) t
      order by orderparentid
      

  12.   


    --借果果数据declare @Lnorder table(OrderParentId int,OrderMoney int)
    insert @Lnorder 
    select 100,500 union all
    select 101,500 union all
    select 101,500 union all
    select 101,500 union all
    select 100,500 union all
    select 100,500 union all
    select 100,500 union all
    select 100,500 union all
    select 103,500 union all
    select 103,500 union all
    select 0,0 
    select top 1 OrderParentId ,sum(OrderMoney) as OrderMoney from @lnorder
    where OrderParentId in(101,103)
    group by OrderParentId 
    order by OrderMoney asc OrderParentId OrderMoney
    ------------- -----------
    103           1000(1 行受影响)