sql - Mysql refrencing derived tables from nested query -


I've posted something like yesterday, but now I want something different from my query -

I am trying to query a database from time to time to get the number of users who visited the website. Data looks something like this:

  day | UserID1 | A1 B2 | B3 | A4 B4 | C5 | D   

I want query results to see

  time span | COUNT (DISTINCT UserID) day 1 to 1 day. 2 days 1 to 2 days. 1 day to 1 day. 0 days 1 day 4 | 1 day 1 day 5 | 2   

The result is 2,1,0,1,2, because at the end of those days, the number of users who visit once. Like for Day 5, at the end of Day 5, user C and D have visited each one once.

I think I am searching for a question like this: Choose d.day, (From day to day visitor (separate userid), Where day & lt; = d.day) (choose days different from visit) d

The difference between the above question and what I am seeing is that I want to query this new query Would like to consider users who use only once for each time period, and do not repeat users I will

Thanks

This subquery should work for explicit requirements. Choose d.day, counting (different conditions when B.Eurid is empty, A. User End) (Choose days from day to day visit) De Inner Join (One On Day B. A, Day, A, User, C. (*) from Visit B visits B at a.userid = b.userid and b.day & lt; = a.day group a.day, a.userid (* ) = 1) A on a. Day & lt; = D.day left (visit a visit from a.day, a.userid, count (*) c to A.userid = b.userid and b.day & lt; = a.day by group A.day, a.userid count (*)> gt 1) b on a.userid = b.userid and b.day & lt; = D.day by group d.day

original

You may have taken the idea from the SQL server - this is the only RDBMS (IIRC) that you were removed twice ( Nesting) query. Please tell what you want and we can rewrite the query.

shown for the exact question, you do not need a sub-class of 2 levels

  SELECT C.col_c1 as data, (from select count (col_b1) Tbl WHERE col_b2 & lt; = c.col_c1) Select one (col_c1 # subquery from CLA 1 to CD1 separately for col_c1) C;    

Comments