Query And Group By

hi
i got an error of :
sub_query expression not allowed in group by
 
  SELECT 
            B.COST_CENTER,
           (select acc_no from STK_MJ where MJ_GR in (
select mj_gr from STK_GRP where grp_no
in (select GRP_NO from stk_item where ITEM_NO =  A.item_no))) Acc_No,
sum((A.av_cost * A.QTY)) Amount
             
           
       FROM STK_TRD A, STK_TRH B
      WHERE     A.TR_YEAR = B.TR_YEAR
            AND A.TR_DATE = B.TR_DATE
            AND A.TR_NO = B.TR_NO
            AND a.stk_no = b.stk_no
            AND a.tr_type = b.tr_type
            and b.tr_type = 2
            AND A.TR_DATE >= '01-apr-15'
            AND A.TR_DATE <= '30-apr-15'
            and b.stk_no = '101'
   group BY B.COST_CENTER,
    (select acc_no from STK_MJ where MJ_GR in (
select mj_gr from STK_GRP where grp_no
in (select GRP_NO from stk_item where ITEM_NO =  A.item_no)))
order by  B.COST_CENTER;

Open in new window

NiceMan331Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
Move the SUM to an outer query.

something like this:
select cost_center, acc_no, sum((av_cost * QTY)) Amount
from(
  SELECT 
            B.COST_CENTER,
           (select acc_no from STK_MJ where MJ_GR in (
select mj_gr from STK_GRP where grp_no
in (select GRP_NO from stk_item where ITEM_NO =  A.item_no))) Acc_No,
A.av_cost, A.QTY
       FROM STK_TRD A, STK_TRH B
      WHERE     A.TR_YEAR = B.TR_YEAR
            AND A.TR_DATE = B.TR_DATE
            AND A.TR_NO = B.TR_NO
            AND a.stk_no = b.stk_no
            AND a.tr_type = b.tr_type
            and b.tr_type = 2
            AND A.TR_DATE >= '01-apr-15'
            AND A.TR_DATE <= '30-apr-15'
            and b.stk_no = '101'
)
group BY COST_CENTER, ACC_NO
order by COST_CENTER;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NiceMan331Author Commented:
Absulate correct , thanx
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.