每当使用call_back_date值创建计划时,我都会插入一行
la_id
每行都相同,我希望获得最新的max(call_back_date)
行
我编写了这个查询,在内部连接三个表之后获取这些调度的所有条目:
SELECT
la_details.application_no,
la_details.id la_det,
la_details.client_id client_id,
la_details.la_name la_name,
la_details.sex sex,
la_details.advisor_name advisor_name,
la_details.client_phone client_phone,
la_details.client_mobile client_mibile,
la_details.level level,
la_details.state state,
la_details.pin_code pin_code,
trans_schedules.id schedule_id,
trans_schedules.*,
comments.descriptions
FROM
la_details
INNER JOIN trans_schedules
ON
trans_schedules.la_id=la_details.id
INNER JOIN comments
ON
comments.comment_id=trans_schedules.comment_id
WHERE
(trans_schedules.comment_id<>'1'
OR
trans_schedules.list_followup = '1'
OR
trans_schedules.counter_flag='0')
AND
la_details.case_closed='0'
ORDER BY
trans_schedules.call_back_date
) a1 INNER JOIN
(
SELECT la_id,MAX(call_back_date) AS call_back_date from
trans_schedules group by la_id
) b1 on a1.la_det = b1.la_id and a1.call_back_date = b1.call_back_date
我的问题是如何在先前的查询中使用子查询来获取最大的call_back_date行 在此先感谢您的帮助!!!!
答案 0 :(得分:0)
对于MySQL:
选择LAST_INSERT_ID();
它将为您提供最后插入的身份记录