Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2010
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Join with group by question

    Code:
    select GUNAG,MSS,KBB,sum(LKK) as SALE from table1
    		where BANDT = 'dtdt'
    			group by GUNAG,MSS,KBB
    With the above sql,let say I have another table which is table2, the relation key is table1.vl and table2.vl. Table2 has amount field and I need to get the value of amount field.

    I tried with this below, I think this will not work. How should I write the query?

    Code:
    select table2.amount,table1.GUNAG,table1.MSS,table1.KBB,sum(table1.LKK) as SALE from table1
    join table2 on table1.vl=table2.vl
    		where table1.BANDT = 'dtdt'
    			group by table1.GUNAG,table1.MSS,table1.KBB

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,487
    Thanks
    23
    Thanked 636 Times in 635 Posts
    Looks good to me. Doing a SELECT query will not hurt the DB. You can run these to see if it works all day long.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •