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

  • Home
  • SEARCH
  • 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 8302827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:22:53+00:00 2026-06-08T17:22:53+00:00

A logistic regression is a composed of a uniquely identifying number, followed by multiple

  • 0

A logistic regression is a composed of a uniquely identifying number, followed by multiple binary variables (always 1 or 0) based on whether or not a person meets certain criteria. Below I have a query that lists several of these binary conditions. With only four such criteria the query takes a little longer to run than what I would think. Is there a more efficient approach than below? Note. tblicd is a large table lookup table with text representations of 15k+ rows. The query makes no real sense, just a proof of concept. I have the proper indexes on my composite keys.

select  patient.patientid 
,case when exists
(
    select c.patientid from tblclaims as c
    inner join patient as p on p.patientid=c.patientid
    and c.admissiondate = p.admissiondate
    and c.dischargedate = p.dischargedate
    where patient.patientid = p.patientid
    group by c.patientid
    having count(*) > 1000
    )
    then '1' else '0'
    end as moreThan1000
,case when exists
(
    select c.patientid from tblclaims as c
    inner join patient as p on p.patientid=c.patientid
    and c.admissiondate = p.admissiondate
    and c.dischargedate = p.dischargedate
    where patient.patientid = p.patientid
    group by c.patientid
    having count(*) > 1500
    )
    then '1' else '0'
    end as moreThan1500
,case when exists
(
    select distinct picd.patientid from patienticd as picd
    inner join patient as p on p.patientid= picd.patientid
    and picd.admissiondate = p.admissiondate
    and picd.dischargedate = p.dischargedate
    inner join tblicd as t on t.icd_id = picd.icd_id
    where t.descrip like '%diabetes%' and patient.patientid = picd.patientid
    )
    then '1' else '0'
    end as diabetes
,case when exists
(
    select r.patientid, count(*) from patient as r
    where r.patientid = patient.patientid
    group by r.patientid
    having count(*) >1
    ) 
    then '1' else '0'
    end 


from patient
order by moreThan1000 desc
  • 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-06-08T17:22:54+00:00Added an answer on June 8, 2026 at 5:22 pm

    I would start by using subqueries in the from clause:

    select q.patientid, moreThan1000, moreThan1500,
           (case when d.patientid is not null then 1 else 0 end),
           (case when pc.patientid is not null then 1 else 0 end)
    from patient p left outer join
         (select c.patientid,
                 (case when count(*) > 1000 then 1 else 0 end) as moreThan1000,
                 (case when count(*) > 1500 then 1 else 0 end) as moreThan1500
          from tblclaims as c inner join
               patient as p
               on p.patientid=c.patientid and
                  c.admissiondate = p.admissiondate and
                  c.dischargedate = p.dischargedate
          group by c.patientid
         ) q
         on p.patientid = q.patientid left outer join
         (select distinct picd.patientid
          from patienticd as picd inner join
               patient as p
               on p.patientid= picd.patientid and
                  picd.admissiondate = p.admissiondate and
                  picd.dischargedate = p.dischargedate inner join
              tblicd as t
              on t.icd_id = picd.icd_id
          where t.descrip like '%diabetes%'
         ) d
         on p.patientid = d.patientid left outer join
         (select r.patientid, count(*) as cnt
          from patient as r
          group by r.patientid
          having count(*) >1
         ) pc
         on p.patientid = pc.patientid
    order by 2 desc
    

    You can then probably simplify these subqueries more by combining them (for instance “p” and “pc” on the outer query can be combined into one). However, without the correlated subqueries, SQL Server should find it easier to optimize the queries.

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

Sidebar

Related Questions

I fit a Logistic Regression Model and train the model based on training dataset
I am running a logistic regression in R and doing backward elimination inorder to
I've trained a simple logistic regression model in SSAS, using Gender and NIC as
I am having problem developing intuition about the probabilistic interpretation of logistic regression. Specifically,
I am doing logistic regression in R. Can somebody clarify what is the differences
I'm trying to make this logistic regression graph in ggplot2 . df <- structure(list(y
I am attempting to run a pooled logistic regression with panel data and a
I'd like to do large-scale regression (linear/logistic) in R with many (e.g. 100k) features,
In linear or logistic regression if we find a hypothesis function which fits the
I am playing around with logistic regression in Python. I have implemented a version

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.