需求:把用戶表和接待表合并,但是只需要顯示每個用戶的最近一次接待。
目前只能做到顯示每個用戶的所有接待。
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



uj5u.com熱心網友回復:
select distinct b.idtable_yonghu,b.yonghuID,b.yonghu_name,
(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
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/92401.html
標籤:MySQL
下一篇:登錄頁面測驗案例
