Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2008
    Posts
    17

    Unanswered: total rows with group by

    Hi,

    i need to have total rows of this query :
    Code:
    select f_date,avg(f_val) from _table where f_type = 1 group by f_date order by f_date
    but this query , return something else :
    Code:
    select count(*) from _table where f_type = 1 group by f_date
    any suggestion ?

  2. #2
    Join Date
    Dec 2007
    Location
    London, UK
    Posts
    741
    Code:
    SELECT f_date, AVG(f_val) avg_val, COUNT(*) cnt_val
    FROM _table
    WHERE f_type = 1
    GROUP BY f_date
    ORDER BY f_date ;

  3. #3
    Join Date
    Nov 2008
    Posts
    17
    dportas, your query give me the total rows for each date ! i dont need this , i need total dates for specific f_type .

    also i dont need any field ! i just need total available dates for specific f_type ! to have one value returned !

    thanx .

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    SELECT COUNT(DISTINCT f_date) FROM daTable WHERE f_type = 1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Nov 2008
    Posts
    17
    Thanx rudy ! greate code !

Posting Permissions

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