이런 쿼리문 혹시 가능한가요?
본문
$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
한방에 가져오는 것.
// $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>";
// $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";
$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>";
}
!-->
답변을 작성하시기 전에 로그인 해주세요.