city_statistics.txt
3 years ago
city_statistics_with_woocommerce.txt
3 years ago
country_statistics.txt
3 years ago
create_referrer.txt
3 years ago
create_resource.txt
3 years ago
create_session.txt
3 years ago
create_view.txt
3 years ago
create_visitor.txt
3 years ago
get_campaign.txt
3 years ago
get_campaigns.txt
3 years ago
get_campaigns_with_woocommerce.txt
3 years ago
get_current_session.txt
3 years ago
get_current_traffic.txt
3 years ago
get_referrer.txt
3 years ago
get_referrers.txt
3 years ago
get_referrers_with_woocommerce.txt
3 years ago
get_resource.txt
3 years ago
get_resources.txt
3 years ago
get_visitors_by_minute_interval.txt
3 years ago
get_visitors_by_ten_second_interval.txt
3 years ago
get_resources.txt
42 lines
| 1 | SELECT * |
| 2 | FROM ( SELECT COUNT(DISTINCT IF(views.current_period, views.id, NULL)) AS views, |
| 3 | COUNT(DISTINCT IF(views.current_period, sessions.visitor_id, NULL)) AS visitors, |
| 4 | COUNT(DISTINCT IF(views.current_period, sessions.session_id, NULL)) AS sessions, |
| 5 | COUNT(DISTINCT IF(comments.current_period, comments.comment_id, NULL)) AS comments, |
| 6 | COUNT(DISTINCT |
| 7 | IF(views.previous_period, views.id, NULL)) AS prev_period_views, |
| 8 | COUNT(DISTINCT |
| 9 | IF(views.previous_period, sessions.visitor_id, NULL)) AS prev_period_visitors, |
| 10 | COUNT(DISTINCT |
| 11 | IF(views.previous_period, sessions.session_id, NULL)) AS prev_period_sessions, |
| 12 | COUNT(DISTINCT |
| 13 | IF(comments.previous_period, comments.comment_id, NULL)) AS prev_period_comments, |
| 14 | resources.* |
| 15 | FROM ( SELECT views.*, |
| 16 | IF(views.viewed_at BETWEEN :start AND :end, TRUE, FALSE) AS current_period, |
| 17 | IF(views.viewed_at BETWEEN :prev_start AND :prev_end, TRUE, |
| 18 | FALSE) AS previous_period |
| 19 | FROM wp_independent_analytics_views AS views |
| 20 | WHERE views.viewed_at BETWEEN :prev_start AND :end |
| 21 | ) AS views |
| 22 | LEFT JOIN wp_independent_analytics_sessions AS sessions |
| 23 | ON views.session_id = sessions.session_id |
| 24 | LEFT JOIN wp_independent_analytics_resources AS resources |
| 25 | ON views.resource_id = resources.id |
| 26 | LEFT JOIN ( SELECT comment_ID AS comment_id, |
| 27 | comment_post_ID AS post_id, |
| 28 | IF(comments.comment_date_gmt BETWEEN :start AND :end, TRUE, |
| 29 | FALSE) AS current_period, |
| 30 | IF(comments.comment_date_gmt BETWEEN :prev_start AND :prev_end, |
| 31 | TRUE, |
| 32 | FALSE) AS previous_period |
| 33 | FROM wp_comments AS comments |
| 34 | WHERE comments.comment_approved = '1' |
| 35 | AND comments.comment_date_gmt BETWEEN :prev_start AND :end |
| 36 | ) AS comments |
| 37 | ON resources.singular_id = comments.post_id |
| 38 | GROUP BY resources.id |
| 39 | ORDER BY visitors DESC, |
| 40 | views DESC |
| 41 | ) subquery |
| 42 | WHERE views > 0 |