Results 1 to 2 of 2

Thread: Simple SQL query, please help!

  1. #1
    Join Date
    Oct 2010
    Posts
    1

    Simple SQL query, please help!

    I am new to SQL so any help would be greatly appreciated.

    So, I have a table which I am trying to summarize in a weird way. Here is the original (using | as the column separator and first row containing the field names):

    ColA |ColB |ColC |ColD |Number |ColF |ColG
    AAA |A1A |1A1 |Apple | 1000 |TEST1 |Value1
    AAA |A1A |1A1 |Orange | 5000 |TEST2 |Value1
    AAA |A1A |1A1 |Banana | -4000 |TEST3 |Value1
    AAA |A1A |23B |Orange | 250 |TEST1 |Value1
    AAA |A1A |23B |Orange | 600 |TEST2 |Value1
    CCC |2A2 |23B |Melon | 750 |TEST2 |Value1

    And here is the result I want:
    ColA |ColB |ColC |Test1 Number |Test3 Number |Number Total |ColD |ColF
    AAA |A1A |1A1 | 1000 | -4000 | 2000 |Apple |TEST1
    AAA |A1A |23B | 250 | 0 | 850 |Orange |TEST1
    CCC |2A2 |23B | 0 | 0 | 750 |Melon |TEST2

    1. Basically, I want to summarize on ColA, ColB and ColC; 3 different combinations, so 3 lines in the result.
    2. For the selected values of ColF, I want to subtotal the "Number" column. I want to call them Test1_Number and Test3_Number for "TEST1" and "TEST3" values respectively.
    3. ColD and ColF in the result only keep the value from the first row. It doesn't not matter what the other lines have.
    4. I don't want ColG in my result.

    I'm sure it's simple, I just don't know SQL... I'm trying to learn.

    Any help would be greatly appreciated. Thanks a lot in advance!

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938

Tags for this Thread

Posting Permissions

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