如何在同一个SQL语句里写呢?

解决方案 »

  1.   

    不行啊,加了一个group by后出错了
    Server: Msg 8120, Level 16, State 1, Line 1
    Column 'tab.dishname' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
    Server: Msg 8120, Level 16, State 1, Line 1
    Column 'tab.stylenum' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
    Server: Msg 8120, Level 16, State 1, Line 1
    Column 'tab.quant' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
    Server: Msg 8120, Level 16, State 1, Line 1
    Column 'dish.dedute' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
      

  2.   

    select XXX from 
    (          ----你的查询语句
    select tab.* ,dish.dedute from
                          (select dishnum,dishname,stylenum,'quant'=count(*)
                           from saledetail 
                           where (saleid in(select saleid 
                                            from salemaster 
                                            where (saledate>='20021116000000')  and (saledate<'20021117000000')and        (posnum='001')))and (spid='001') Group by dishnum,dishname,stylenum)as tab 
    left outer join dish on (dish.number=tab.dishnum)and (dish.spec=tab.stylenum)) temptable group by XXXX
      

  3.   

    select 你的分组列,你的计算列 from (
    select tab.* ,dish.dedute from
                          (select dishnum,dishname,stylenum,'quant'=count(*)
                           from saledetail 
                           where (saleid in(select saleid 
                                            from salemaster 
                                            where (saledate>='20021116000000')  and (saledate<'20021117000000')and        (posnum='001')))and (spid='001') Group by dishnum,dishname,stylenum)as tab 
    left outer join dish on (dish.number=tab.dishnum)and (dish.spec=tab.stylenum)
    )A group by 你的分组列
      

  4.   

    对一个已进入RECORDSET的结果集还能再分组吗? 不用临时表如何实现? 采用子查询最后还是要存入一个REDORDSET的呀?