에서 ROW_NUMBER()를 사용하여 :PostgreSQL의 : 나는 자신의 "가상 돈"으로 분류되어 플레이어의 목록을 표시하는 PHP 스크립트를 페이징 출력
$sth = $db->prepare("
select u.id,
u.first_name,
u.city,
u.avatar,
m.money,
u.login > u.logout as online
from pref_users u, pref_money m where
m.yw=to_char(current_timestamp, 'IYYY-IW') and
u.id=m.id
order by m.money desc
limit 20 offset ?
");
$sth->execute(array($_GET['offset']));
나는 PHP 변수를 사용하여 목록에서 플레이어의 위치를 표시하려면 $ pos는 이름과 그 이상의 데이터를 인쇄하는 동안 루프에서 증가합니다.
저는 여러 가지 이유로 PHP 대신 SQL 문에서 그 위치를 원합니다.
$sth = $db->prepare("
select u.id,
row_number() + ? as pos,
u.first_name,
u.city,
u.avatar,
m.money,
u.login > u.logout as online
from pref_users u, pref_money m where
m.yw=to_char(current_timestamp, 'IYYY-IW') and
u.id=m.id
order by m.money desc
limit 20 offset ?
");
$sth->execute(array($_GET['offset'], $_GET['offset']));
그러나 오류 얻을 : 그래서 나는 다음과 같은 노력하고있어 나는 (m.money) 이상 를 추가하지만 얻으려고 오버 절
필요 창 함수 호출을 구문 오류.
나는 아마도 Window Functions 의사를 오해하고 있습니다.
무엇 "구문 오류"입니까? 그리고 어떤 구문을 시도 했습니까? OVER와 ORDER BY를 사용해야하고, 당신이 한 일을 보여주십시오. OVER (ORDER BY m.money ASC) –
@nate c : PHP에서 준비된 문으로 SQL 삽입이 문제가 될 것이라고 생각하지 않습니다. –