순위 구하는 sql 문 문의 채택완료
답변 2개
위 코드는 순위내는데는 아무 소용없는 것 같은데요?
순위는 아래처럼 하면 됩니다만 로그인 스킨 같은 곳에 넣어서 페이지 이동할 때 마다 순위를
계산하게 하는 것은 아주 무식한 짓입니다
실시간으로 순위를 내야하는 용도가 아니라면 로그인 할 때(login_check.php) 회원 테이블 여분필드에
구한 등위를 넣어두고 사용하는 방법으로 하면 될 것입니다
그리고 회원수가 제법되고 포인트 내역이 많으면 쓸데없이 join하는 것은 느리게만 만들뿐입니다
-- 1000, 500, 500, 300 이게 포인트면 500점은 2등, 300점은 4등이 되어야할테죠?
$po_rel_table = '@member';
$result = sql_query(" select sum(po_point) as po_point_sum, mb_id from {$g5['point_table']} where po_datetime > (now() - INTERVAL 7 DAY) and po_rel_table = '$po_rel_table' group by mb_id order by po_point_sum desc");
$nn = 0;
while($row=sql_fetch_array($result)){ $nn++;
if($pre_point != $row[po_point_sum]) $gd =$nn;
$pre_point = $row[po_point_sum];
if($member[mb_id] == $row[mb_id]){ $my_grade = $gd; break;}
}
echo "등위:".$my_grade.'==>'.$member[mb_id];
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
서브쿼리가 된다면 이렇게 해도되겠습니다
$row = sql_fetch(" select sum(po_point) as po_tot, mb_id from {$g5['point_table']} where mb_id = '{$member['mb_id']}' and po_datetime > (now() - INTERVAL 7 DAY) and po_rel_table = '$po_rel_table' ");
$row2 = sql_fetch(" select count(*) as cnt from (select sum(po_point) as po_point_sum from {$g5['point_table']} where po_datetime > (now() - INTERVAL 7 DAY) and po_rel_table = '$po_rel_table' group by mb_id) as b where b.po_point_sum > '$row[po_tot]' ");
echo '나의 등위:' .($row2[cnt]+1).'<===> 포인트: '.$row[po_tot];
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인