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 313587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:07:18+00:00 2026-05-12T08:07:18+00:00

update: changed one time to show that the times per shipment may not be

  • 0

update: changed one time to show that the times per shipment may not be in sequential order always.

here is my input

create table test
(
    shipment_id int,
    stop_seq tinyint,
    time datetime
)

insert into test values (1,1,'2009-8-10 8:00:00')
insert into test values (1,2,'2009-8-10 9:00:00')
insert into test values (1,3,'2009-8-10 10:00:00')
insert into test values (2,1,'2009-8-10 13:00:00')
insert into test values (2,2,'2009-8-10 14:00:00')
insert into test values (2,3,'2009-8-10 20:00:00')
insert into test values (2,4,'2009-8-10 18:00:00')

the output that i want is below

shipment_id  start    end
-----------  -----    ---
     1        8:00    10:00
     2        13:00   18:00

i need to take the time from the min(stop) row for each shipment and the time from the max(stop) row and place in start/end respectively. i know this can be done with multiple queries rather easily but i am looking to see if a single select query can do this.

thanks!

  • 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-12T08:07:19+00:00Added an answer on May 12, 2026 at 8:07 am

    I think the only way you’ll be able to do it is with sub-queries.

    SELECT shipment_id
        , (SELECT TOP 1 time 
            FROM test AS [b] 
            WHERE b.shipment_id = a.shipment_id 
            AND b.stop_seq = MIN(a.stop_seq)) AS [start]
        , (SELECT TOP 1 time 
            FROM test AS [b] 
            WHERE b.shipment_id = a.shipment_id 
            AND b.stop_seq = MAX(a.stop_seq)) AS [end]
    FROM test AS [a]
    GROUP BY shipment_id
    

    You’ll need to use the DATEPART function to chop up the time column to get your exact output.

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

Sidebar

Related Questions

I need this query - update last but one record. UPDATE changes SET checked=''
UPDATE: I've changed the wording of the question. Previously it was a yes/no question
I have a listview which has its datasource changed after update of a search
UPDATE: Facebook's API has changed a lot since this question was posted. This question
I changed hdd1\Content folder with JTAG console, how to restore and update this folder,
I've trouble getting my components to update when the params has changed: package mycompany
UPDATE: OK I figured it out, looks like fread has a filesize limitation, changed
What is a correct way to update model when view changed. Is it need
I'm having issues getting Firefox to update a webpage when its class is changed
How can I get changed attributes (name, old value, new value) on update using

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.