Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2007
    Posts
    25

    Arrow Unanswered: Can I GROUP BY aggregate Function (Like SUM)

    Hello,

    I column that calculated at run time in insert , can i gruop by this column,the new one that not exist yet

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    yes, with a derived table, but why would you want to?

    please show an example, using sample data to illustrate
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jul 2007
    Posts
    25
    this is my case:

    i have a table with a column datetime (I use to record time of calls) , i want to create table that hold data for each hour, so i round the column and want to group by this column in the same time

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you can round a datetime? please show your query
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jul 2007
    Posts
    25
    This is the Query of round datetime

    DATEADD(Hour, DATEDIFF(Hour, 0, cdrCallDate), 0)
    You can change [hour] to day , minutes , second , etc...

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    yes, you can GROUP BY that expression

    and you cannot use second, it causes an overflow

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Jul 2007
    Posts
    25
    thanks man for this information

Posting Permissions

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