sql 질문입니다..(카운트세기)

sql 질문입니다..(카운트세기)

QA

sql 질문입니다..(카운트세기)

본문


<?
$query = "SELECT * FROM g5_board_new where dateco_id != '' and dateco_id != 'epro' and dateco_id != 'admin'  ORDER BY wr_id desc";
$sql = sql_query($query);
$state_1 = sql_fetch(" select count(*) as cnt from {$g5['board_new_table']} where addarea='작업지시' ");

?>
<style type="text/css">

*{
padding:0;
margin:0;
}

table, tr, td{ border: 1px solid #ddd;

}

</style>

	<table class="table table-bordered">
		<tr>
			<th >아이디</th>
			<th >작업지시</th>
			<th >승인대기</th>
			<th >승인완료</th>
			<th >승인거절</th>
			<th >작업완료</th>
			<th >기간만료</th>
		</tr>
		<?php while($row= sql_fetch_array($sql)) { ?> 
		<tr> 
			<td><?php echo $row["dateco_id"]; ?></td> 
			<td> <?php echo $state_1['cnt']?></td> 
		</tr> <?php } ?> 

	</table>


질문은 이러합니다.

g5_board_new에 있는 아이디를 뿌리고, 그 아이디와 연결된 단어들의 숫자를 같이 뿌리고 싶습니다. 


예)

아이디

작업지시 

승인대기 

승인완료 

 홍길동

10 

 0

 장길산

10

 1

 임꺽정

 20

이런식으로 해당아이디와 연결되는 단어의 숫자를 세고 싶습니다.



위 코드를 작성하면 g5_board_new에 있는 아이디는 정상적으로 뿌려집니다.

근데 그 아이디에 연결되는 단어의 숫자를 어떻게 뿌려야할지 감이 안잡혀서요,,, 

혹시 도움을 구할 수 잇을까요?

아님 불가능한가요?


이 질문에 댓글 쓰기 :

답변 4

이런건 제작의뢰에 가까운 내용이지만.. 열정을 봐서 




<?php
$query = "SELECT 
                   x.dateco_id, 
                   (select count(*) from g5_board_new a 
                              where a.dateco_id = x.dateco_id and addarea='작업지시') workcnt, 


                   (select count(*) from g5_board_new a 
                              where a.dateco_id = x.dateco_id and addarea='승인대기') staycnt, 


                   (select count(*) from g5_board_new a 
                              where a.dateco_id = x.dateco_id and addarea='승인완료') endcnt
               FROM (select distinct dateco_id g5_board_new 
                          where dateco_id != '' and dateco_id != 'epro' 
                          and dateco_id != 'admin'  ORDER BY wr_id desc) x";
$sql = sql_query($query);

?>
<style type="text/css">

*{
padding:0;
margin:0;
}

table, tr, td{ border: 1px solid #ddd;

}

</style>

	<table class="table table-bordered">
		<tr>
			<th >아이디</th>
			<th >작업지시</th>
			<th >승인대기</th>
			<th >승인완료</th><!--
			<th >승인거절</th>
			<th >작업완료</th>
			<th >기간만료</th>-->
		</tr>
		<?php while($row= sql_fetch_array($sql)) { ?> 
		<tr> 
			<td><?php echo $row["dateco_id"]; ?></td> 
			<td> <?php echo $row['workcnt']?></td> 
			<td> <?php echo $row['staycnt']?></td> 
			<td> <?php echo $row['endcnt']?></td> 
		</tr> <?php } ?> 

	</table>

하시면
원하는 값들을 사용하실수있습니다.



동일한 구조로
방문자의 카운트를 확인하는걸 보여드리면 무슨차이가 있는지 직접 확인가능하실겁니다.



select vi_ip, 
(select count(a.vi_id) from g5_visit a where a.vi_date = curdate() and x.vi_ip = a.vi_ip) today,
(select count(a.vi_id) from g5_visit a where a.vi_date between '2017-01-01' and curdate() and x.vi_ip = a.vi_ip) toyear
from (select distinct vi_ip from g5_visit ) x 


이 코드가 보이시면 위의 내용이 정상인지 확인 가능하지 않을까요?



			   "select dateco_id, 
(select count(a.dateco_id) from g5_board_new a where a.dateco_id = x.dateco_id and addarea='작업지시') cnt_1,
(select count(a.dateco_id) from g5_board_new a where a.dateco_id = x.dateco_id and addarea='승인대기') cnt_2
from (select distinct dateco_id from g5_board_new where dateco_id != '' and dateco_id != 'epro' and dateco_id != 'admin'  ORDER BY wr_id desc) x ";



이렇게 하니까 되네요!

조언 감사합니다.

이렇게 쿼리 하시면 되는거 아닌가요?


select dateco_id

, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='작업지시') as count_1

, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인대기') as count_2

, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인완료') as count_3 

from g5_board_new out


$query = "위에 쓴 쿼리
 where dateco_id != '' and dateco_id != 'epro' and dateco_id != 'admin'  ORDER BY wr_id desc";
$sql = sql_query($query);

...

<td><?php echo $row["dateco_id"]; ?></td> 
<td><?php echo $row['count_1']?></td> 
<td><?php echo $row['count_2']?></td> 
<td><?php echo $row['count_3']?></td> 


$query = "select dateco_id 
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='작업지시') as count_1
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인대기') as count_2 
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인완료') as count_3
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인거절') as count_4
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='작업완료') as count_5
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='기간만료') as count_6
from g5_board_new out where dateco_id != '' and dateco_id != 'epro' and dateco_id != 'admin'  ORDER BY wr_id desc";
$sql = sql_query($query);

<?php
		$cnt=0;
		while($row= sql_fetch_array($sql)) { 
		?> 
		<tr> 
			<td><?php echo $row['dateco_id']; ?></td> 
			<td><?php echo $row['count_1']?></td>
			<td><?php echo $row['count_2']?></td> 
			<td><?php echo $row['count_3']?></td> 
			<td><?php echo $row['count_4']?></td> 
			<td><?php echo $row['count_5']?></td> 
			<td><?php echo $row['count_6']?></td> 
		</tr>
		<?php  $cnt++;  } ?> 




아무것도 안나오네요...

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

회원로그인

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