SELECT account_id, sabre_log_id as ps,
outlet_count as po
FROM
(
SELECT account_id, outlet_count, sabre_log_id
FROM tbl_sabre_load_log
WHERE sabre_log_id in
(
SELECT max(sabre_log_id) as "sec_log" FROM
tbl_sabre_load_log
WHERE sabre_log_id NOT IN
(SELECT max(sabre_log_id)
FROM tbl_sabre_load_log
GROUP BY account_id
)
GROUP BY account_id
)
) Previous_Week
UNION ALL
SELECT account_id, sabre_log_id as ps,
outlet_count as po
From
(
SELECT account_id, outlet_count, sabre_log_id
FROM tbl_sabre_load_log
WHERE sabre_log_id in
(SELECT max(sabre_log_id)
FROM tbl_sabre_load_log
GROUP BY account_id
)
) Current_Week

SELECT Previous_Week.account_id, Previous_Week.sabre_log_id as ps, Previous_Week.outlet_count as po,
Current_Week.outlet_count as ci, Current_Week.sabre_log_id as cs
FROM
(
SELECT account_id, outlet_count, sabre_log_id
FROM tbl_sabre_load_log
WHERE sabre_log_id in
(
SELECT max(sabre_log_id) as "sec_log" FROM
tbl_sabre_load_log
WHERE sabre_log_id NOT IN
(SELECT max(sabre_log_id)
FROM tbl_sabre_load_log
GROUP BY account_id
)
GROUP BY account_id
)
) Previous_Week
Join
(
SELECT account_id, outlet_count, sabre_log_id
FROM tbl_sabre_load_log
WHERE sabre_log_id in
(SELECT max(sabre_log_id)
FROM tbl_sabre_load_log
GROUP BY account_id
)
) Current_Week
on Previous_Week.account_id = Current_Week.account_id