이런 쿼리문 혹시 가능한가요? 채택완료
Copy
$sql ="select xm_round from g5_write_offroad where xm_round = 'onn' AND xm_no <= 10";
$result = sql_query($sql);
$on1 = sql_num_rows($result);
저렇게 해서..xm_no <=10 조건으로 갯수를 구하고 있는데요.
$on1 : xm_no <=10 까지의 갯수
$on2 : xm_no <=20 까지의 갯수
$on3 : xm_no <=30 까지의 갯수...
이런식으로 각각 값을 구할수 있나요?
답변 3개
채택된 답변
+20 포인트
HappyTank
5년 전
한방에 가져오는 것.
Copy
// $on1 : xm_no <=10 까지의 갯수
// $on2 : xm_no <=20 까지의 갯수
// $on3 : xm_no <=30 까지의 갯수
$sql ="select count(xm_round) AS on1, 0 AS on2, 0 AS on3 from g5_write_offroad where xm_round = 'onn' AND xm_no <= 10
UNION ALL
select 0 AS on1, count(xm_round) AS on2, 0 AS on3 from g5_write_offroad where xm_round = 'onn' AND xm_no <= 20
UNION ALL
select 0 AS on1, 0 AS on2, count(xm_round) AS on3 from g5_write_offroad where xm_round = 'onn' AND xm_no <= 30";
$row = sql_fetch($sql);
echo "on1 : ".$row['on1']."<BR>";
echo "on2 : ".$row['on2']."<BR>";
echo "on3 : ".$row['on3']."<BR>";
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
5년 전
Copy
$sql ="select 'on1' type, count(xm_round) cnt from g5_write_offroad where xm_round = 'onn' AND xm_no <= 10
union all
select 'on2' type, count(xm_round) cnt from g5_write_offroad where xm_round = 'onn' AND xm_no <=20
union all
select 'on3' type, count(xm_round) cnt from g5_write_offroad where xm_round = 'onn' AND xm_no <= 30
order by type ";
$result = sql_query($sql);
while ($row = sql_fetch_array($result)) {
echo "type : ".$row['type']." : ".$row['cnt']."<BR>";
}
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
HappyTank
5년 전
Copy
// $on1 : xm_no <=10 까지의 갯수
$sql ="select count(xm_round) from g5_write_offroad where xm_round = 'onn' AND xm_no <= 10";
// $on2 : xm_no <=20 까지의 갯수
$sql ="select count(xm_round) from g5_write_offroad where xm_round = 'onn' AND xm_no <= 20";
// $on3 : xm_no <=30 까지의 갯수...
$sql ="select count(xm_round) from g5_write_offroad where xm_round = 'onn' AND xm_no <= 30";
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
5년 전
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
쿼리문 하나로 각각의 값을 얻을수 있는지 알고 싶었거든요...
소중한 답변 감사드립니다.