tough going with group to get result

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dragrid
    New Member
    • Jan 2009
    • 29

    tough going with group to get result

    Hi Anyone - need your help
    i would like a query to list two main columns Atime and endtime - query to group the start times and endtime separately - even though the table start out with corresponding start time and end times. table is thousand of lines vary times
    Also would like to get say the top times of each Fri Sat Sun of each week in each month over a period of time say 3 months
    so for example - first week end in Feb, table would look like below
    ATIME EndTIME

    2010-02-05 00:03 2010-02-05 00:16
    2010-02-05 00:03 2010-02-05 00:16
    2010-02-05 00:03 2010-02-06 00:55
    2010-02-05 00:03 2010-02-06 00:55
    2010-02-06 00:05 2010-02-06 00:55
    2010-02-06 00:05 2010-02-06 00:55
    2010-02-06 00:05 2010-02-07 00:08
    2010-02-07 00:02 2010-02-07 00:08
    2010-02-07 00:02 2010-02-07 00:08

    query I have only go as far as ( don't care for sec or mili sec )

    Code:
    select convert(varchar(16)Atime,120) as stime, count(stime),convert(varcher(16)endtime,120) as etime, count(etime) 
    From table
    Where (ATIME >= '2010-02-01 00:00:00') and (ATIME <= '2010-02-28 23:59:59') 
    and datename(weekday,ATIME) in ( 'Friday','Saturday','Sunday')
    group by convert(varchar(16)Atime,120), convert(varchar(16)endtime,120)

    My columns in table looks like this
    ATIME EndTIME

    Atime endtime
    2010-02-05 00:00:01.000 2010-02-05 00:00:11.000
    2010-02-05 00:00:04.000 2010-02-05 01:00:04.000
    2010-02-05 00:00:05.000 2010-02-05 00:40:05.000
    2010-02-05 00:00:06.000 2010-02-05 02:10:00.000
    2010-02-05 00:00:07.000 2010-02-05 00:09:08.000
    2010-02-05 00:00:08.000 2010-02-05 00:20:08.000
    2010-02-05 00:00:08.000 2010-02-05 00:30:08.000
    2010-02-05 00:00:11.000 2010-02-05 00:50:11.000
    2010-02-05 00:00:12.000 2010-02-05 01:11:02.000
    2010-02-05 00:00:13.000 2010-02-05 00:55:43.000
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    What's the unique key that hold this table together?

    ~~ CK

    Comment

    • dragrid
      New Member
      • Jan 2009
      • 29

      #3
      Hey CK it is an ID number with six digits like 654321

      Comment

      • dragrid
        New Member
        • Jan 2009
        • 29

        #4
        CK , anyone - I think I can figure out a way to solve query first part - but can you help me on the second part - so I need the top say 10 or whatever results for Fri Sat and Sun - each day - not the over all top 10 for all three days combined which means Sat could have seven out of the ten - need 10 for Fri , 10 for Sat, 10 for Sun

        Comment

        • ck9663
          Recognized Expert Specialist
          • Jun 2007
          • 2878

          #5
          Try a 3 union-ized query with the TOP clause on each.

          Happy Coding!!!

          ~~ CK

          Comment

          Working...