sql - How to combine different queries results into a single query result table -


Here's one thing. I'm trying to find a query that can include all 3 results. But second only how to query for one of them. Question: At least 200 members participate: Provide the following information for each survey: 1) survey ID and survey details 2) Number of members starting the survey 3) Number.

Find survey_id, Survey_desc,

Tbl_survey, Tbl_member_participation from TOTALNUMBER where tbl-survey.member_id = Tbl_member_participation.member_id survey_id, being Survey_desc being TOTALNUMBER & gt as Group (Tbl_survey.member_id); = 200

2) Queries for the number of subscribers started but did not end.

  Select count (select_id) from Tbl_survey, where survey_id exists (Survey_ID, survey_desk, count (Tbl_survey.member_id) Select Tbl_survey, Tbl_member_participation as the total number where tbl-survey Member_id = Tbl_member_participation.member_id survey_id, Survey_desc being group by TOTALNUMBER & gt; = 200) and finishi_date is ** null ** survey_id  by group 

3) That's already finished.

 Tbl_survey, where survey_id exists (select_id) from survey_id selection, survey_id, Survey_desc, Tbl_survey, Tbl_member_participation counted as TOTALNUMBER where tbl-survey.member_id = Survey_id, Survey_desc being TOTALNUMBER & gt; Tbl_member_participation.member_id Group, = 200) and finishi_date *** is not empty *** group by survey_id  

So I just wanted to combine these alliances You can do three results like survey ID, survey details, people start, end people. In only one query table.

First of all, you should correct your questions.

1) Your first query is fine, but you should not use joining separate outdated comma syntax syntax. Obviously get (that's where some twenty years ago introduced in SQL standard, BTW).

  select s.survey_id, s.survey_desc, count (*) Tbl_survey from TOTALNUMBER as tbl_member_participation join in mp S.member_id = mp.member_id s.survey_id on group , Count on s.survey_desc (*)> = 200;  

2,3) Your second and third questions are really broken. You are mixing in a way EXISTS and in addition it is likely to be a member of the finishedi_date tbl_member_participation, so you should re-join this table.

  select s.survey_id, count (*) from tbl_survey s.member_id = mp.member_id to join tbl_member_participation mp in where survey_id (s.survey_id) is selected from tbl_survey s: here Query 2 is correct on S.member_id = mp.member_id s.survey_id group (*) & gt; = 200), join tbl_member_participation mp and mp.finishi_date s.survey_id is a null group;  

To combine all three, you do not need to use EXISTS or IN. All required data 1 is already available in the query. Look, how much I modify query 1 to get 2 simple query:

  select s.survey_id, sum (case when mp.finishi_date is zero then 1 and 0 end) count_unfinished from tbl_survey S s.member_id = mp.member_id count by ssurvey_id on group (*)> = 200; Join tbl_member_participation mp when done;  

After saying this, your last query is:

  select s.survey_id, s.survey_desc, sum (case when mp.finishi_date is zero As a count of some other 0) count_unfinished, yoga (case when mp.finishi_date is not empty, count 1finded) and count_finished as * tumber_survey from * TOTALNUMBER s.member_id = mp.member_id on group by tbl_member_participation mp Count as joining () .survey_id, s.survey_desc Count (*)> = 200;  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -