Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4991

Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4993

Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php:4991) in /www/htdocs/v030397/mysql-qotd/wp-includes/feed-rss2-comments.php on line 8
Comments on: Question 83: How to get the correct price? http://mysql-qotd.casperia.net/archives/537 mysql 5.0/5.1 questions for learning purposes Fri, 06 Aug 2010 16:56:36 +0000 http://wordpress.org/?v=abc hourly 1 By: plogi http://mysql-qotd.casperia.net/archives/537/comment-page-1#comment-94 plogi Mon, 12 Jul 2010 18:08:09 +0000 http://mysql-qotd.casperia.net/?p=537#comment-94 <b> This query left joins the log against the prices using the valid from/to dates. The left join is there to catch occurences, when there is no price. <small><pre> select date(v1.sold_ts) as dd,sum(v2.price),count(*), sum(if(v2.price is null,1,0)) as prices_missing from vending_log v1 left join vending_price v2 on (v1.product_id = v2.product_id and date(v1.sold_ts) between v2.valid_from and v2.valid_to) group by dd; </pre></small> </b>
This query left joins the log against the prices using the valid from/to dates.
The left join is there to catch occurences, when there is no price.

select date(v1.sold_ts) as dd,sum(v2.price),count(*),
       sum(if(v2.price is null,1,0)) as prices_missing
from vending_log v1 left join vending_price v2 on
  (v1.product_id = v2.product_id and
   date(v1.sold_ts) between v2.valid_from and v2.valid_to)
group by dd;


]]>