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
    283
    Thanks
    2
    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. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    6,282
    Thanks
    30
    Thanked 863 Times in 861 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.
    Physics is actually atoms trying to understand themselves.


 

Posting Permissions

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