Tuesday, December 21, 2010

SAS ADV 63题之43


Item 43 of 63 Mark item for review 

  Given the SAS data set WORK.ONE:      

      Rep         Cost 
      -----       ---- 
      SMITH        200 
      SMITH        400 
      JONES        100 
      SMITH        600 
      JONES        100 

  The following SAS program is submitted:

  proc sql;  
     select  
        Rep, 
        avg(Cost) as Average   
     from WORK.ONE     
     [either__insert_SQL_where_clause_]     
     group by Rep
     [_or_  _insert_SQL_having_clause_]
     ;
  quit;

  The following output is desired:       

      Rep        Average
      -----      -------
      SMITH          400

  Which SQL clause completes the program and generates the desired output?     


     A.
 where calculated Average > (select avg(Cost) from WORK.ONE)

     B.
 having Average   > (select avg(Cost) from WORK.ONE)

     C.
 having avg(Cost) < (select avg(Cost) from WORK.ONE)

     D.
 where avg(Cost)  > (select avg(Cost) from WORK.ONE)

这道题主要考察关于having和where的知识。 

having的用法: 和group搭配使用。group用来把data分成subset,having用来选择符合条件的subset. 所以having何以和summary function一起用,比如sum, avg之类的

where的用法: where只能用之与单独的列,不能和summary function一起用

所以答案应该是:B

1 comment: