이런 쿼리문 혹시 가능한가요?

이런 쿼리문 혹시 가능한가요?

QA

이런 쿼리문 혹시 가능한가요?

본문


$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>";
}
 

 

 

답변을 작성하시기 전에 로그인 해주세요.
전체 123,535 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT