Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. WITH uniqueips(frst, lst, ip, visits) AS
  2. (
  3. SELECT MIN(requested_on), MAX(requested_on), ip, count(*) AS visits
  4. FROM Page_Statistic p
  5. GROUP BY ip
  6. ),
  7. tried_demo(ip, tried_demo) AS
  8. (
  9. SELECT DISTINCT ip.ip, ISNULL(p.page_statistic_id - p.page_statistic_id + 1, 0)
  10. FROM uniqueips ip
  11. LEFT JOIN Page_Statistic p ON p.ip = ip.ip AND p.tag = 'demo'
  12. )
  13. SELECT
  14. i.*, ip.frst AS first_appeared_on,
  15. ip.lst AS last_appeared_on,
  16. ip.visits,
  17. d.tried_demo
  18. FROM Ip_Location_Info i
  19. JOIN uniqueips ip ON ip.ip = i.ip
  20. JOIN tried_demo d ON ip.ip = d.ip
  21. ORDER BY ip.frst
  22.  
  23. ISNULL(p.page_statistic_id - p.page_statistic_id + 1, 0)
  24.  
  25. case when p.page_statistic_id is null then 0 else 1 end
  26.  
  27. tried_demo(ip, tried_demo) AS
  28. (
  29. SELECT DISTINCT p.ip, cast(1 as bit)
  30. FROM Page_Statistic
  31. WHERE p.tag = 'demo'
  32. )
  33.  
  34. SELECT
  35. i.*, ip.frst AS first_appeared_on,
  36. ip.lst AS last_appeared_on,
  37. ip.visits,
  38. coalesce(d.tried_demo,0) as tried_demo
  39. FROM Ip_Location_Info i
  40. JOIN uniqueips ip ON ip.ip = i.ip
  41. LEFT JOIN tried_demo d ON ip.ip = d.ip
  42. ORDER BY ip.frst
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement