需求:把用户表和接待表合并,但是只需要显示每个用户的最近一次接待。
目前只能做到显示每个用户的所有接待。
SELECT distinct table_yonghu.idtable_yonghu, table_yonghu.yonghuID, table_yonghu.yonghu_name,
table_reception.riqi
FROM table_reception, table_yonghu
where table_yonghu.yonghuID = table_reception.yonghuID
and table_yonghu.isdeleted = 0 and table_reception.riqi > '2018-4-10' and table_reception.riqi <
'2018-4-11' and table_reception.dianhao = '0218' and table_reception.jinshouren = '店长'
order by table_reception.idtable_reception desc
目前只能做到显示每个用户的所有接待。
SELECT distinct table_yonghu.idtable_yonghu, table_yonghu.yonghuID, table_yonghu.yonghu_name,
table_reception.riqi
FROM table_reception, table_yonghu
where table_yonghu.yonghuID = table_reception.yonghuID
and table_yonghu.isdeleted = 0 and table_reception.riqi > '2018-4-10' and table_reception.riqi <
'2018-4-11' and table_reception.dianhao = '0218' and table_reception.jinshouren = '店长'
order by table_reception.idtable_reception desc
(select max(a.riqi) from table_reception a where a.yonghuID = b.yonghuID and a.riqi > '2018-4-10' and a.riqi < '2018-4-11' and a.dianhao = '0218' and a.jinshouren = '店长') as jiedai
from table_yonghu b
where isdeleted = 0 order by jiedai desc