Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6866555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:11:55+00:00 2026-05-27T03:11:55+00:00

I have a query like this: SELECT Weighings.Member, MIN(Sessions.DateTime) AS FirstDate, MAX(Sessions.DateTime) AS LastDate

  • 0

I have a query like this:

SELECT Weighings.Member, MIN(Sessions.DateTime) AS FirstDate, MAX(Sessions.DateTime) AS LastDate
FROM Weighings AS Weighings INNER JOIN
     Sessions ON Sessions.SessionGUID = Weighings.Session
WHERE     (Sessions.DateTime >= '01/01/2011')
GROUP BY Weighings.Member
ORDER BY Weighings.Member

It returns this:

Member | FirstDate | LastDate
Blah   | 01/01/11  | 06/07/11
Blah2  | 02/03/11  | 05/07/11

I need to get the value of a cell Weight_kg in table Weighings for the returned values FirstDate and LastDate to give results like so:

Member | FirstWeight | LastWeight
Blah   | 150Kg       | 60KG
Blah2  | 70Kg        | 72KG

I have tried all combinations of things but just can’t work it out, any ideas?

EDIT

Tables:

Sessions
______________________
SessionGUID | DateTime
----------------------
12432524325 | 01/01/11
12432524324 | 01/08/11
12432524323 | 01/15/11
34257473563 | 03/05/11
43634574545 | 06/07/11

Weighings
_____________________________________
Member      | Session     | Weight_kg
-------------------------------------
vffd8fdg87f | 12432524325 | 150
vffd8fdg87f | 12432524324 | 120
vffd8fdg87f | 12432524323 | 110
ddffv89sdv8 | 34257473563 | 124
32878vfdsv8 | 43634574545 | 75
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:11:56+00:00Added an answer on May 27, 2026 at 3:11 am
    ;with C as
    (
      select W.Member,
             W.Weight_kg,
             row_number() over(partition by W.Member order by S.datetime desc) as rnLast,
             row_number() over(partition by W.Member order by S.datetime asc) as rnFirst
      from Weighings as W
        inner join Sessions as S
          on S.sessionguid = W.Session and
             S.DateTime >= '20110101'
    )
    select CF.Member,
           CF.Weight_kg as FirstWeight,
           CL.Weight_kg as LastWeigth
    from C as CF
      inner join C as CL
        on CF.Member = CL.Member
    where CF.rnFirst = 1 and
          CL.rnLast = 1
    

    Try here: https://data.stackexchange.com/stackoverflow/q/118518/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a query like this: SELECT DATEPART(year,some_date), DATEPART(month,some_date), MAX(some_value) max_value FROM some_table GROUP
I have an MySQL query like this: SELECT MAX(messages.ID) as maxID, messages.from, messages.read, users.userName
I have a query like this: SELECT c.id, c.name, f.name FROM companies c INNER
I have a query like this: SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM MY_DB.INFORMATION_SCHEMA.COLUMNS WHERE
I have a query like this: SELECT t1.id, (SELECT COUNT(t2.id) FROM t2 WHERE t2.id
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales
I have a simple query like this: select * from mytable where id >
I have a query like this: SELECT name FROM mytable WHERE id = $id
I have a query like this: SELECT TaFellesVaktjournal.*, TaBygg.ByggNavn FROM TaFellesVaktjournal LEFT JOIN TaBygg
I have a query like this: SELECT X.Y( 'p1', 'p2', 'p3', 'p4', '100') FROM

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.