group by 사용하는 방법 부탁드려요^^ 정보
group by 사용하는 방법 부탁드려요^^본문
$sql = " select * from $bo_write_table group by ca_name where wr_datetime between '$fr_date 00:00:00' and '$to_date 23:59:59' order by wr_datetime desc";
$result = sql_query($sql);
for ($i=0; $row = sql_fetch_array($result); $i++) {
$rank = $rank + 1;
$w6 = $row[wr_6]; //재적
$row_wr_6=$row_wr_6 + $w6;
$w13 = $row[wr_13]; //총출석
$row_wr_13=$row_wr_13 + $w13;
$gul=$row_wr_6 - $row_wr_13 ; //결석
$evg1=$row_wr_13 / $rank; //평균
$evg = number_format($evg1, 2);
$w8 = $row[wr_8]; //신입
$row_wr_8=$row_wr_8 + $w8;
$per=($row_wr_13 / $row_wr_6) * 100 ; //백분율
$per1 = number_format($per, 2);
$wr_datetime = $row[wr_datetime];
$ca_name=$row[ca_name];
// ca_name같으면 여기까지
?>
<tr class="bg<?=$bg?>">
<td class="count">
<?=$ca_name?></td>
<td class="count"><?=$row_wr_6?></td>
<td class="count"><?=$row_wr_13?></td>
<td class="count"><?=$gul?></td>
<td class="count"><?=$evg?></td>
<td class="count"><?=$row_wr_8?></td>
<td class="count"><?=$per1?></td>
<td class="count"><?= $wr_datetime?></td>
</tr>
<?}?>
---------------------------------
1. $sql = " select * from $bo_write_table where wr_datetime between '$fr_date 00:00:00' and '$to_date 23:59:59' order by wr_datetime desc";
이렇게 하면 원하는 출력이 됩니다만
ca_name의 전체값들이 계속 누적되어 출력됩니다
2. $sql = " select * from $bo_write_table group by ca_name where wr_datetime between '$fr_date 00:00:00' and '$to_date 23:59:59' order by wr_datetime desc";
이렇게 하면 에러가 나오네요
select * from g4_write_today group by ca_name where wr_datetime between '2012-07-03 00:00:00' and '2012-08-03 23:59:59' order by wr_datetime desc
1064 : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'where wr_datetime between '2012-07-03 00:00:00' and '2012-08-03
3. 입력되는 기간안에 같은 ca_name 값을 누적하여 출력하고픈데
잘 안되네요
고수님들의 자세한 정보를 구합니다 감좌^^
$result = sql_query($sql);
for ($i=0; $row = sql_fetch_array($result); $i++) {
$rank = $rank + 1;
$w6 = $row[wr_6]; //재적
$row_wr_6=$row_wr_6 + $w6;
$w13 = $row[wr_13]; //총출석
$row_wr_13=$row_wr_13 + $w13;
$gul=$row_wr_6 - $row_wr_13 ; //결석
$evg1=$row_wr_13 / $rank; //평균
$evg = number_format($evg1, 2);
$w8 = $row[wr_8]; //신입
$row_wr_8=$row_wr_8 + $w8;
$per=($row_wr_13 / $row_wr_6) * 100 ; //백분율
$per1 = number_format($per, 2);
$wr_datetime = $row[wr_datetime];
$ca_name=$row[ca_name];
// ca_name같으면 여기까지
?>
<tr class="bg<?=$bg?>">
<td class="count">
<?=$ca_name?></td>
<td class="count"><?=$row_wr_6?></td>
<td class="count"><?=$row_wr_13?></td>
<td class="count"><?=$gul?></td>
<td class="count"><?=$evg?></td>
<td class="count"><?=$row_wr_8?></td>
<td class="count"><?=$per1?></td>
<td class="count"><?= $wr_datetime?></td>
</tr>
<?}?>
---------------------------------
1. $sql = " select * from $bo_write_table where wr_datetime between '$fr_date 00:00:00' and '$to_date 23:59:59' order by wr_datetime desc";
이렇게 하면 원하는 출력이 됩니다만
ca_name의 전체값들이 계속 누적되어 출력됩니다
2. $sql = " select * from $bo_write_table group by ca_name where wr_datetime between '$fr_date 00:00:00' and '$to_date 23:59:59' order by wr_datetime desc";
이렇게 하면 에러가 나오네요
select * from g4_write_today group by ca_name where wr_datetime between '2012-07-03 00:00:00' and '2012-08-03 23:59:59' order by wr_datetime desc
1064 : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'where wr_datetime between '2012-07-03 00:00:00' and '2012-08-03
3. 입력되는 기간안에 같은 ca_name 값을 누적하여 출력하고픈데
잘 안되네요
고수님들의 자세한 정보를 구합니다 감좌^^
댓글 전체

지금 쓰신 쿼리를 보니
mysql 기본기가 좀 부족하신거 같습니다.
답을 알려드리려고 하기 보다는 검색을 좀더 해보심이 좋을꺼 같습니다
http://www.google.com/search?complete=1&hl=ko&q=mysql group by&lr=&aq=null#q=mysql+group+by&hl=ko&lr=lang_ko&complete=1&prmd=imvns&source=lnt&tbs=lr:lang_1ko&sa=X&ei=f8gbUMGrN8-QiAeKn4CQAw&ved=0CFUQpwUoAQ&bav=on.2,or.r_gc.r_pw.&fp=f4d7e0dd9d864d1f&biw=1680&bih=819
위 링크 가시면 mysql group by 에 대한 각종 정보가 아주 많이 나옵니다.
mysql 기본기가 좀 부족하신거 같습니다.
답을 알려드리려고 하기 보다는 검색을 좀더 해보심이 좋을꺼 같습니다
http://www.google.com/search?complete=1&hl=ko&q=mysql group by&lr=&aq=null#q=mysql+group+by&hl=ko&lr=lang_ko&complete=1&prmd=imvns&source=lnt&tbs=lr:lang_1ko&sa=X&ei=f8gbUMGrN8-QiAeKn4CQAw&ved=0CFUQpwUoAQ&bav=on.2,or.r_gc.r_pw.&fp=f4d7e0dd9d864d1f&biw=1680&bih=819
위 링크 가시면 mysql group by 에 대한 각종 정보가 아주 많이 나옵니다.
$sql = " select * from $bo_write_table wr_datetime where wr_datetime between '$fr_date 00:00:00' and '$to_date 23:59:59' ";
요거를 그룹으로 출력하고 싶은데요
넓은마인드님 알려주신 사이트정보 넘감사드립니다
아무리 해봐도 잘안돼네요
요거를 그룹으로 출력하고 싶은데요
넓은마인드님 알려주신 사이트정보 넘감사드립니다
아무리 해봐도 잘안돼네요