2 つのテーブルから SUM/Total レコードを 1 か月に 1 日に取得したいのですが、1 つのテーブルでクエリを実行すると機能しますが、commulative が機能しません。
select DATE_FORMAT(date(dateadded),'%m/%d/%Y') as dateadded, count(id) as tot_rent
from crm_rentals WHERE YEAR(dateadded) = YEAR(CURRENT_DATE)
AND MONTH(dateadded) = MONTH(CURRENT_DATE)
group by date(dateadded)
これは 2 番目のテーブル用です。これも問題ありません。
select DATE_FORMAT(date(dateadded),'%m/%d/%Y') as dateadded, count(id) as tot_rent
from crm_sales WHERE YEAR(dateadded) = YEAR(CURRENT_DATE)
AND MONTH(dateadded) = MONTH(CURRENT_DATE)
group by date(dateadded)
問題は、結果の毎日の合計を見つけたいときですが、正しく機能していません..ここに私の最終的なクエリがあります
select dateadded,count(tot_rent) as tot_rent
from ( select DATE_FORMAT(date(dateadded),'%m/%d/%Y') as dateadded, count(id) as tot_rent
from crm_rentals WHERE YEAR(dateadded) = YEAR(CURRENT_DATE)
AND MONTH(dateadded) = MONTH(CURRENT_DATE)
group by date(dateadded)
union
select DATE_FORMAT(date(dateadded),'%m/%d/%Y') as dateadded, count(id) as tot_rent
from crm_sales WHERE YEAR(dateadded) = YEAR(CURRENT_DATE)
AND MONTH(dateadded) = MONTH(CURRENT_DATE)
group by date(dateadded)) s group by date(dateadded)
crm_rentals のテーブル構造 (最初のテーブル、日付 = Ymd)
id -----dateadded
15------2013-04-02
16------2013-04-03
17------2013-04-03
表 2 crm_sales
id------dateadded
7------2013-04-02
結果は
dateadded-----tot_rent
04/02/2013 ----2
04/03/2013 ---2 //this line is not shown