Results 1 to 4 of 4

Thread: Group by clause

  1. #1
    Join Date
    Aug 2004
    Posts
    1

    Angry Group by clause

    I have this result whith this sql

    --------------------------------------
    NAME Start_date End_date min(score)
    --------------------------------------
    JOHN 02/2002 03/2002 150
    JOHN 03/2002 04/2002 55
    JOHN 04/2002 05/2002 100

    from 2 tables

    SELECT t1.name, t2.start_date, t2.end_date, min(t2.score) from t1,t2
    where t1.name = t2.name
    group by t1.name, t2.start_date, t2.end_date

    But I just want have one record whith the period of the min score:

    --------------------------------------
    NAME Start_date End_date min(score)
    --------------------------------------
    JOHN 03/2002 04/2002 55


    Have you an idea ?
    Last edited by glac; 08-25-2004 at 09:47 AM.

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You have to use derived table.

    Also all the columns returned are in t2, you don't need to join to t1.


    select t2.name, t2.start_date, t2.end_date
    from t2 as t2
    join
    (select name, min(score) as minscore
    from t2
    group by name) as t
    on t2.name = t.name
    and t2.score = t.minscore

  3. #3
    Join Date
    Sep 2004
    Posts
    7
    It may be late.... but this could be another solution

    SELECT DISTINCT T2.NAME, T2.START_DATE, T2.END_DATE, T2.SCORE
    FROM T2
    WHERE (name,score) IN
    (SELECT name,min(score)
    FROM T2
    GROUP BY NAME
    )

    - Vinita

  4. #4
    Join Date
    Oct 2004
    Location
    Pune
    Posts
    1
    Try this one and let me know

    SELECT DISTINCT T2.NAME, T2.START_DATE, T2.END_DATE, T2.SCORE
    FROM T2
    WHERE t1.name=t2.name
    AND T2.score=(select min(score) from T2)
    /

Posting Permissions

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