Tuesday 15 April 2014

mysql - Complex querying on table with multiple userids -


I have a table like this:

  Week's status of score ID 1 1 0 2 1 1 3 1 0 4 1 0 1 2 2 2 2 1 3 2 0 4 2 1 1 3 1 2 3 1 3 3 1 4 3 0  

I get all the IDs Those who have zero status for all week other than the week. Something like this:

Result:

  Result: ID w1.status w2.status w3.status 1 0 0 1 3 0 0 1  

I have this question, but it is very inefficient on large datasets.

  select w1.id, w1.status, w2.status, w3.status (s.id, s.status score, s.week = 1) w1 left JOIN (Select s.id, s.status score by WHERE s.week = 2) w1.id = w2.id on w2 (selection s.id, s.status score where s.week = 3) on w3 W1.id = w3.id WHERE w1.status = 0 and w2.status = 0 and w3.status = 1  

I look for a more efficient method to calculate the above I am here.

  select the digits from the ID, where in the week (1, 2, 3) ( In case when the week (1, 2) and position = 0 then 1 when week = 3 and position = 1 then 1 and 0 end) = 3  

or more generally ... Select the ID from the score group through ID (case = 0 then in case 1 and 0) = count (*) - 1 and min (case when position = 1 then tap end of the week) = maximum (week) < / Code>


No comments:

Post a Comment