Begginer Question

  • I have a table with the following colums

    DATE_PROCESS | MEASURE_HOUR | MAX_TOTAL_USAGE

    (This is Date) (This time in Hrs) (This is Numeric)

    I need to create a query to get the MaxUsage of the

    of the day and what hour it is:

    So far I was able to create the query below below: but it only show the particular Max_Total_Usage per Day. I also need to see what hour it is.

    SELECT max(TOTAL_USAGE) as MAX_TOTAL_USAGE, DATE_PROCESS

    from dbo.avayautilizationtbl

    WHERE

    and DATE_PROCESS >= '2007-10-01 00:00:00.000'

    and DATE_PROCESS <= '2007-10-31 00:00:00.000'

    group by DATE_PROCESS

    order by DATE_PROCESS

    Hope anyone can help me solve my problem.

    Thank you so much.

  • Welcome to SQL servercentral 🙂

    Please click on the link in my sig for help on how to post to get the best results.

    could you give us some sample data and what you expect as out put 🙂

    thanks

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • Hi There,

    I would try something like;

    WITH GroupBY_CTE AS

    (

    SELECT max(TOTAL_USAGE) as MAX_TOTAL_USAGE, DATE_PROCESS

    from dbo.avayautilizationtbl

    WHERE

    and DATE_PROCESS >= '2007-10-01 00:00:00.000'

    and DATE_PROCESS <= '2007-10-31 00:00:00.000'

    group by DATE_PROCESS

    order by DATE_PROCESS

    )

    SELECT A.DATE_PROCESS,

    A.MEASURE_HOUR,

    A.MAX_TOTAL_USAGE

    FROM dbo.avayautilizationtbl A INNER JOIN GroupBY_CTE G ON

    A.DATE_PROCESS = G.DATE_PROCESS AND

    A.MAX_TOTAL_USAGE = G.MAX_TOTAL_USAGE

    I didn't test the above, so it may not work exactly as is.

    Not sure if you can do this in a single query.

    Josh

    Mao Says RTFM

  • Firstly, from where do I get the MEASURE_HOUR value? Does the DATE_PROCESS column will have time portions too?

    Without much information, the sample data and the required outputs, it would be difficult to provide you with the correct solutions.

    Here, I am posting the query from what I understood....

    SELECTDATE_PROCESS, HOUR( DATE_PROCESS ) AS MEASURE_HOUR,

    MAX( TOTAL_USAGE ) AS MAX_TOTAL_USAGE

    FROMdbo.avayautilizationtbl

    WHEREDATE_PROCESS >= '2007-10-01 00:00:00.000'

    AND DATE_PROCESS <= '2007-10-31 00:00:00.000'

    GROUP BY DATE_PROCESS, HOUR( DATE_PROCESS )

    ORDER BY DATE_PROCESS, MEASURE_HOUR

    --Ramesh


  • Thank you so much for all the reply.

    So sorry If my post is not so good.

    I will follow the guidelines given by Christopher Stobbs.

    I was able to solve my problem using the solution posted by ShuaThe2nd

    Again Thank you so much.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply