Combining mysql queries that recycle multiple self joins -


I have the following set of a MySQL query, which is used to track the user's progress through the website is. Is it a good way to make them easy?

  # How many people choose phase 2 as a form of "total" as the COUNT (separate one session_id) form______, where one. Progress = 2 and DATE (A.datetime) = "2011-03-23"; # How many people have reached stage 4, select step 2 "as a total (as a session_id), formation_payment_ights, (SELECT f.session_id, f.datetime) form___fits_fits f ou.progress = 2) WHERE a.progress = 4 and a.session_id = b.session_id and DATE (b.datetime) = "2011-03-23" and DATE (a.datetime) = "2011-03-23" # # People reached Phase 7, after arriving at step 4, select step 2, forming "total" as the "total" form_date (select one f.session_id, f.tatetime) while reaching step 1 ) From form__f_fits_fits where F progress = 4) b In form, the form___fits_fits f (f.progress = 2) from WHERE a.progress = 7 and a.session_id = b.session_id and a.session_id = c. Session_id and (SELECT f.session_id, f.tatetime) DATE (c.datetime) = "2011-03-23" and DATE (b.datetime) = "2011-03-23" and DATE (a.datetime) = "2011-03-23";  < / Pre> 

As you can see, I am querying the same information again and there are an additional 4 or 5 questions that follow the same pattern - is there a better way to build it there? Query means to "How many people have reached Stage 2" Do not have to keep the inquiry?

Edit: Each page view is stored as an entry in form__page_hits - so that the full record of page views for each session is

  id_formation_page_hits INT PRIMARY_KEY, session_id VARCHAR (100), DATETIME from day to day, progress INT    

by group (session_id, that time, progress) Work faster for

Comments