테스트 사이트 - 개발 중인 베타 버전입니다

sql 쿼리 문의~ 채택완료

오토고고 3년 전 조회 2,454

안녕하세요?

쿼리에서 sum을 사용중입니다.

그런데 실제로는 합한 값이 0.5여야 하는데 반올림된 1로 표시하는 문제가 있습니다.

0.5로 표현하려면 어떻게 해야 하나요?

제가 사용한 쿼리는 아래와 같습니다.

 

 

http://u109.ivyro.net/webmysql/phpMyAdmin/url.php?url=http://dev.mysql.com/doc/refman/5.5/en/select.html" target="mysql_doc">select sum(vday_float) as tx from vac_rep_days as da inner join kgstec_vac_rep as rep on da.vrep_idx = rep.vrep_idx where rep.mb_no = '33' http://u109.ivyro.net/webmysql/phpMyAdmin/url.php?url=http://dev.mysql.com/doc/refman/5.5/en/logical-operators.html#operator_and" target="mysql_doc">and vac_idx = '0' http://u109.ivyro.net/webmysql/phpMyAdmin/url.php?url=http://dev.mysql.com/doc/refman/5.5/en/logical-operators.html#operator_and" target="mysql_doc">and vday_date<= '2022-06-28' http://u109.ivyro.net/webmysql/phpMyAdmin/url.php?url=http://dev.mysql.com/doc/refman/5.5/en/logical-operators.html#operator_and" target="mysql_doc">and vrep_status = '결재완료' http://u109.ivyro.net/webmysql/phpMyAdmin/url.php?url=http://dev.mysql.com/doc/refman/5.5/en/logical-operators.html#operator_and" target="mysql_doc">and vday_date http://u109.ivyro.net/webmysql/phpMyAdmin/url.php?url=http://dev.mysql.com/doc/refman/5.5/en/string-comparison-functions.html#operator_like" target="mysql_doc">like '2022%'

댓글을 작성하려면 로그인이 필요합니다.

답변 4개

채택된 답변
+20 포인트
3년 전

q1 값이 나오게 TRUNCATE . 1  해보세요

</strong></p>

<p>select TRUNCATE(sum(tb.aaa), <strong>1</strong>) as q1

, TRUNCATE(sum(tb.aaa), 0) as q2 

from 

(

select 1.2 aaa

union all select 1.4 aaa

) tb </p>

<p><strong>

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

복스리
3년 전

mysql 로 들아가서 해당 필드(vday_float)가 float형이나 double인지 먼저 확인을 해보시기 바랍니다.

그리고 정수형으로 정확하게 표현을 하기 위해서 join을 하기전 먼 조건에 맞는 테이블 끼리 sum을 한번 해보시신 후 양쪽 테이블에서 정수값이 아닌 소숫점 숫자로 정확하게  노출되는지도 먼저 확인해보시기 후에 

join 조건을 성립하여 확이해보시면 해당 문제는 해결될꺼 같습니다. 

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

3년 전

q1 값이 나오게 TRUNCATE . 1  해보세요

 

select TRUNCATE(sum(tb.aaa), 1) as q1
, TRUNCATE(sum(tb.aaa), 0) as q2 
from 
(
select 1.2 aaa
union all select 1.4 aaa
) tb 

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

출력하는 php? 소스는 어떻게 되나요?

날짜 조건은

http://u109.ivyro.net/webmysql/phpMyAdmin/url.php?url=http://dev.mysql.com/doc/refman/5.5/en/logical-operators.html#operator_and" rel="nofollow">and vday_date bewteen '2022-01-01' and '2022-06-28'

하시는 것이 좋습니다.

 

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인