我必须显示列Visit_Date的最大日期 如果我搜索“2013-10-29”,那么记录显示这些客户的日期为“2013-10-29” 但在coloumn我必须显示客户的最长日期
答案 0 :(得分:2)
这......
SELECT
P_Master.PID,
Visit_Date,
(SELECT MAX(Visit_Date) FROM P_Visit v WHERE v.PID = p_Master.PID) as MaxVisit
FROM P_Master
LEFT JOIN P_VISIT
ON P_Master.PID=P_VISIT.PID
WHERE CAST(CONVERT(varchar(10), Visit_Date, 101) AS datetime)='2013-10-29'
...添加一个包含最近访问日期的列
答案 1 :(得分:1)
SELECT
P_Master.PID,
Visit_Date FROM P_Master
LEFT JOIN P_VISIT
on Visit_Date=(SELECT MAX(Visit_Date) FROM [dbo].[P_Visit] WHERE P_Master.PID=P_VISIT.PID )
答案 2 :(得分:1)
试试这个:
SELECT
P_Master.PID,
(SELECT MAX(Visit_Date) FROM P_Master
LEFT JOIN P_VISIT ON P_Master.PID=P_VISIT.PID) AS VISIT_DATE
FROM P_Master
LEFT JOIN P_VISIT
ON P_Master.PID=P_VISIT.PID
WHERE CAST(CONVERT(varchar(10), Visit_Date, 101) AS datetime)='2013-10-29'
答案 3 :(得分:-1)
SELECT
P_Master.PID,
MAX(Visit_Date) FROM P_Master
LEFT JOIN P_VISIT
ON P_Master.PID=P_VISIT.PID
将为您提供每位访客的最新访问