mysql - SQL: count progressively unique visits from table -


i have table (visits):

id  |       fb_id    |   flipbook    |  ----     ----------      ---------      1         1123           november2014         2         1123           november2014       3         1127           november2014        4         1124           november2014     5         1126           november2014             6         1123           december2014 7         1124           december2014 8         1125           december2014 9         1123           january2015   10         1124           january2015 11        1125           january2015 12         1123           february2015 13         1125           february2015 14        1124           february2015 15        1127           february2015 16        1129           march2015 17        1123           march2015 18        1123           march2015 19        1124           march2015 20        1125           march2015 21        1126           march2015 22        1128           march2015 

we have 5 flipbooks in total, , after query want following results:

5: 10 (because have 2 users visited flipbooks = 10 visits) 4: 4 (only 1 user visited 4 flipbooks = 4 visits) 3: 0 2: 4 (2 users visited  2 flipbook = 4 visits ) 1: 2 (2 users visited 1 flipbook = 2 visits) 

i don't have query in mind post here achive result, ideas?

i create subquery counts distinct flipbooks fb_id. outer query count inner counts , multiply them well. can use concat() function if want results in single field t.visited:no_of_visits format without additional subquery.

select t.visited, count(t.visited) * t.visited no_of_visits     (select fb_id, count(distinct flipbook) visited      vistits group fb_id) t group t.visited 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -