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

The Archive Base Latest Questions

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

I want to select patient_id and date difference from below table: p_id TreatmentDate 15

  • 0

I want to select patient_id and date difference from below table:

p_id    TreatmentDate
15      2008-05-01
15      2008-05-03
15      2008-05-05
15      2008-05-07
16      2008-05-01
16      2008-05-03
16      2008-05-05
16      2008-05-09
16      2008-05-11
17      2008-05-03
17      2008-05-05
17      2008-05-07

I want to have this result:

p_id      Day Difference
15        6 Days
16        10 Days
17        4 Days

Do you have any offer that can generate this result in sql statement?

  • 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-12T14:15:08+00:00Added an answer on May 12, 2026 at 2:15 pm

    This should work in general

    select p_id, max(TreatmentDate) - min(TreatmentDate) from 
    patientsTable group by p_id
    

    more specifically, for MSSQL Server

    select p_id, DATEDIFF(D, MIN(TreatmentDate), MAX(TreatmentDate)) from 
    patientsTable group by p_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is the output i want SELECT * FROM wateat_tbl where name like '%love%'
I have some following set of data from where I want to select Top
I want select multiple (all) values from table Account. string query = SELECT *
I want to select all the Female patients from the patient table where the
select distinct * from Drivers where IsDeleted=0 gives me this, alt text http://www.imagechicken.com/uploads/1274691753099236100.jpg I
I have a small database which is legacy from an almost defunct project. This
So I got this statement, which works fine: SELECT MAX(patient_history_date_bio) AS med_date, medication_name FROM
In a nutshell: I have some database table data that I want to populate
Hi i want to get changed text value from JQuery but i can't select
I'm having trouble trying to define the SQL query for this table: There's a

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.