location /nodejs {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:N;
proxy_redirect off;
}
SELECT ads.*, COUNT(DISTINCT clicks.id) as clicks, COUNT(DISTINCT shows.id) as shows, (COUNT(DISTINCT clicks.id) * COUNT(DISTINCT shows.id))/100 as CTR
FROM ads
LEFT JOIN shows ON ads.id = shows.ad_id
LEFT JOIN clicks ON ads.id = clicks.ad_id AND shows.created_at = clicks.created_at
WHERE shows.created_at = '2014-02-24'
GROUP BY ads.id