select tmp.`date`, tmp.code, daily.daily_id
from( select code, `date` from daily group by code, `date` ) tmp
left join daily on daily.code=tmp.code and daily.date=tmp.`date`
where daily.daily_id is null
ปล. date เอา backquote ครอบ ด้วยนะครับ เป็น คำพิเศษ
แก้ไขโค๊ดหน่อย พอดีรีบไปรับลูกสาว
และ ได้ ตาราง store มาด้วย ก็จบล่ะ
Code (SQL)
select tmp.`date`, tmp.code, daily.daily_id
from
(
select d1.storecode code, d2.`date`
from store d1 , (select `date` from daily group by `date` ) d2
) tmp
left join daily on daily.code=tmp.code and daily.date=tmp.`date`
where daily.daily_id is null
select tmp.`date`, tmp.code, daily.daily_id
from( select code, `date` from daily group by code, `date` ) tmp
left join daily on daily.code=tmp.code and daily.date=tmp.`date`
where daily.daily_id is null
แก้เป็น
Code (SQL)
select tmp.`date`, tmp.code, daily.daily_id
from
(
select d1.code, d2.`date`
from ( select code from daily group by code ) d1 , (select `date` from daily group by `date` ) d2
) tmp
left join daily on daily.code=tmp.code and daily.date=tmp.`date`
where daily.daily_id is null
$qr=' select tmp.`date`, tmp.code, daily.daily_id
from
(
select d1.code, d2.`date`
from ( select code from daily group by code ) d1 , (select `date` from daily group by `date` ) d2
) tmp
left join daily on daily.code=tmp.code and daily.date=tmp.`date`
where daily.daily_id is null ';
$qr=' select tmp.`date`, tmp.code, daily.daily_id
from
(
select d1.code, d2.`date`
from ( select code from daily group by code ) d1 , (select `date` from daily group by `date` ) d2
) tmp
left join daily on daily.code=tmp.code and daily.date=tmp.`date`
where daily.daily_id is null ';
$query = mysql_query($qr);
$result = mysql_fetch_assoc($query);
mysql_error();