Dear Vixens and Reynards:

     An innocent-looking query:
          select;
           clcode,;
           sum(basicchg+ovrhdfee) as totamount,;
           sum(quantity) as sumqty,;
           totamount/sumqty as avgunit;
          from cwkt;
          group by clcode;
          order by clcode
Unfortunately, it is not legal.  Instead, I have to do:
          select;
           clcode,;
           sum(basicchg+ovrhdfee) as totamount,;
           sum(quantity) as sumqty,;
           sum(basicchg+ovrhdfee)/sum(quantity) as avgunit;
          from cwkt;
          group by clcode;
          order by clcode
(The change is in the definition of avgunit.)

Apparently, I can not use the totamount and sumqty names in the columns clause. Oddly enough, I can use them in the order by clause (and maybe elsewhere). This is legal:
          select;
           clcode,;
           sum(basicchg+ovrhdfee) as totamount,;
           sum(quantity) as sumqty,;
           sum(basicchg+ovrhdfee)/sum(quantity) as avgunit;
          from cwkt;
          group by clcode;
          order by avgunit

     Is this really how it is, or am I overlooking something?

Sincerely,

Gene Wirchenko


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to