Skip to content

Instantly share code, notes, and snippets.

@ibejohn818
Last active June 13, 2016 23:57
Show Gist options
  • Save ibejohn818/227be59e8b19fdb722271270058a4704 to your computer and use it in GitHub Desktop.
Save ibejohn818/227be59e8b19fdb722271270058a4704 to your computer and use it in GitHub Desktop.
Get Pagination position of single record
-- GET THE RANK BASED ON BASE CONDITIONS AND BASE SORT AND DIVIDE BY THE LIMIT ROUNDED UP TO GET PAGE NUMBER
select x.rank
from (
SELECT
`PortalBdReportPosTransactionSummary`.id,
@rownum := @rownum+1 AS rank
FROM
portal_bd_report_pos_transaction_summaries AS `PortalBdReportPosTransactionSummary`, (select @rownum := 0) r
WHERE
`PortalBdReportPosTransactionSummary`.`dvrdatetime` >= '2016-06-09 00:00:00'
AND `PortalBdReportPosTransactionSummary`.`dvrdatetime` < '2016-06-13 00:00:00'
AND `PortalBdReportPosTransactionSummary`.`global_location_id` IN(
881571,
881575,
881576,
881604,
881656,
881661,
881662,
881663,
881664,
881665,
881765,
881798,
881800,
881801,
881802,
881803,
881804,
881805,
881806,
881807,
881808,
881809,
881810,
881811,
881812,
881813,
881814,
881815,
881816,
881817,
881818,
881819,
881820,
881822,
881823,
881824,
881825,
881826
)
ORDER BY
`PortalBdReportPosTransactionSummary`.`dvrdatetime`
) as x where id =5376
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment