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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:52:22+00:00 2026-06-11T14:52:22+00:00

I must select in same table two project.project_dates (one for start and one for

  • 0

I must select in same table two project.project_dates (one for start and one for end) in the table I’ve two fields project.start = true and project.end = true for identify it

What should the SQL query look like?

I have tried:

SELECT 
    pz.cognome AS Cognome,
    (select s.presa_in_carico_data from tbl_progetto s where s.is_progetto = 1 AND                    
        s.cc_id_fk = cc.cc_id) as Start,
    (select e.presa_in_carico_data from tbl_progetto e where e.is_dimissione = 1 AND 
        e.cc_id_fk = cc.cc_id) as End, 
    trf.trf_note AS "Tipo trattam.",
    trf.trf_prezzou as Retta,
    COUNT(tra.trt_id) AS "N.GG." /*<-- this is normal count from date range select from user(#) */
FROM
    tbl_progetto p 
    JOIN tbl_cartellaclinica cc ON cc.cc_id = p.cc_id_fk
    JOIN tbl_paziente pz ON pz.id = cc.pz_fk_id
    JOIN tbl_distretti_sanitari di ON pz.distretto_appartenenza = di.dss_id
    JOIN tbl_trattamenti tra ON p.pr_id = tra.pr_fk_id    
WHERE
    tra.trt_data BETWEEN '2012-08-01' AND '2012-08-31' AND
    p.pr_faseriab_fk = 4
GROUP BY cc_id
  • 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-11T14:52:23+00:00Added an answer on June 11, 2026 at 2:52 pm
    select p.id as ProjectId,
    (select s.date from project_dates s where s.start = true and s.project_id = p.id) as StartDate,
    (select e.date from project_dates e where e.end = true and e.project_id = p.id) as EndDate
    into #temp
    from Project p 
    

    Update:

    To answer your comment, again I have to make assumptions about how things look in your database, but I would do something like this:

    Create a temp-table for storing the result of the above query (see changes).. Then:

    select p.id
           (select count(1) from Meeting m where m.date between '2012-01-01' and '2012-08-31' and m.project_id = p.id) as Count1
           (select count(1) from Meeting m where m.date between (select StartDate from #temp where ProjectId = p.id) and (select EndDate from #temp where ProjectId = p.id) and m.project_id = p.id) as count2
    from Project p 
    [where p.id = <something>]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two forms, one with a radio button that users must select to
I have the query to select some columns from two tables, which must contain
I'm experiencing some weird behavior with SELECT statements in sqlite. There is one table
I'm using C# 2010 Express and Sql Compact. I have two-column table and a
I've got a MySQL table with, among other things, two fields: a (int) and
I'm using two tables for my current project(it will grow certainly). First table has
My table has two keys, one is an auto incrementing id (PRIMARY), the other
Possible Duplicate: every derived table must have its own alias i have two MYSQL
i have a select in linq : in if i must compare username and
I must send a struct between two machines via a udp socket the information

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.