Substitute for First function

  • Looking for assistance, converting from access, I want the first temperature from a list of persons and temperatures; I got it to work if there is only one patient, using below, but there are many temperatures:

    SELECT TOP 1

    MEAS_VALUE, PAT__ID, MIN(RECORDED_TIME) AS 'recorded time'

    FROM teWWWW01.NI__TEMPERATURE_DATA_DUMP

    WHERE (PAT_ID = '123')

    GROUP BY MEAS_VALUE, PAT_ID, RECORDED_TIME

    ORDER BY 'recorded time'

    It was posted to use MIN, but function isn't doing anything, played with using row_number(), but notice to sql, coming from Access.

    Thanks in advance

  • te_<3 (6/17/2015)


    Looking for assistance, converting from access, I want the first temperature from a list of persons and temperatures; I got it to work if there is only one patient, using below, but there are many temperatures:

    SELECT TOP 1

    MEAS_VALUE, PAT__ID, MIN(RECORDED_TIME) AS 'recorded time'

    FROM teWWWW01.NI__TEMPERATURE_DATA_DUMP

    WHERE (PAT_ID = '123')

    GROUP BY MEAS_VALUE, PAT_ID, RECORDED_TIME

    ORDER BY 'recorded time'

    It was posted to use MIN, but function isn't doing anything, played with using row_number(), but notice to sql, coming from Access.

    Thanks in advance

    Quick thought, removing the RECORDED_TIME will probably do the trick.

    😎

  • the point of the query is to get the first temperature or recorded_time

  • This?

    with basedata as (

    select

    MEAS_VALUE,

    PAT_ID,

    RECORDED_TIME,

    rn = row_number() over (partition by PAT_ID order by RECORDED_TIME asc)

    from

    teWWWW01.NI__TEMPERATURE_DATA_DUMP

    )

    select

    MEAS_VALUE,

    PAT_ID,

    RECORDED_TIME

    from

    basedata

    where

    rn = 1;

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

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