Advertisement
tribulant

Untitled

Mar 6th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.25 KB | None | 0 0
  1. SELECT a.id, a.impressions, za.order, za.zone_id
  2.                                     FROM wp_wpbrads AS a
  3.                                     LEFT JOIN wp_wpbrzonesads AS za
  4.                                     ON a.id = za.ad_id
  5.                                     WHERE a.impressions =
  6.                                     (SELECT MAX(a.impressions)
  7.                                     FROM wp_wpbrads AS a
  8.                                     LEFT JOIN wp_wpbrzonesads AS za
  9.                                     ON a.id = za.ad_id WHERE a.impressions < '' AND za.zone_id = '11' AND a.active = 'Y'
  10.                                     AND (a.expiry = '0000-00-00' OR a.expiry >= '2014-03-06')
  11.                                     AND (a.startDate = '0000-00-00' OR a.startDate <= '2014-03-06')
  12.                                     AND (a.impressions = 0 OR a.impressions > a.views) AND a.id != '0')
  13.                                     UNION ALL
  14.                                     SELECT a.id, a.impressions, za.order, za.zone_id
  15.                                     FROM wp_wpbrads AS a
  16.                                     LEFT JOIN wp_wpbrzonesads AS za
  17.                                     ON a.id = za.ad_id
  18.                                     WHERE a.impressions =
  19.                                     (SELECT MAX(a.impressions) FROM wp_wpbrads AS a
  20.                                     LEFT JOIN wp_wpbrzonesads AS za
  21.                                     ON a.id = za.ad_id WHERE za.zone_id = '11' AND a.active = 'Y'
  22.                                     AND (a.expiry = '0000-00-00' OR a.expiry >= '2014-03-06')
  23.                                     AND (a.startDate = '0000-00-00' OR a.startDate <= '2014-03-06')
  24.                                     AND (a.impressions = 0 OR a.impressions > a.views) AND a.id != '0')
  25.                                     ORDER BY impressions ASC LIMIT 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement