Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 0.79 KB | None | 0 0
  1. SELECT  ROUND((COUNT(client_008.doh_places_updated.id)::numeric(16,2)/
  2. (SELECT COUNT(x.id)::numeric(16,2)
  3. FROM client_008.doh_places_updated x
  4. INNER JOIN PUBLIC.places P ON (X.place_id = P.id)
  5. INNER JOIN PUBLIC.markets M ON (P.market_id = M.id)
  6. WHERE (x.doh_date=doh_places_updated.doh_date))::numeric(16,2))*100,2) AS AVG,
  7. retails.id, retails.name, doh_places_updated.doh_date AS format
  8. FROM "client_008"."doh_places_updated"
  9. left join "public"."places" ON places.id = doh_places_updated.place_id
  10. left join "public"."markets" ON markets.id = places.market_id
  11. left join "public"."retails" ON retails.id = markets.retail_id
  12. WHERE "instock_28" = 1 AND
  13. date_trunc('week',doh_places_updated.doh_date::TIMESTAMP) = date_trunc('week','2017-04-30'::TIMESTAMP)
  14. GROUP BY 3,2,4 ORDER BY 2,4 ASC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement