수파베이스 함수 문의 0 2 4,750

by knlim [PL/SQL] 리턴값 라운드 함수 [2024.04.11 21:47:23]


안녕하세요..

수파베이스 함수를 호출해서 평균값을 가져오는 부분입니다.

1번 코드로 하면 정상적으로 avg 값이 정상적으로 출력되는데, 소숫점 자리를 하나로 제한하기 위해서

아래의 2번과 같이 round 함수를 추가하면 데이터를 가져오지 못하는데 이유가 있나요?

 

1번 avg(gmr."correctCount"::float) as avg
2번 round(avg(gmr."correctCount"::float),1) as avg

고수님들 의견 주시면 감사하겠습니다.

create or replace function gamemathrecordstats(gameidpara integer, useridpara uuid, startdate date, enddate date)

returns table(

  gameid int,

  userid uuid,

  max int,

  min int,

  avg float

) as $$

begin

return query

select

  gmr."gameid"::int,

  gmr."userid"::uuid,

  max(gmr."correctCount"::int) as max,

  min(gmr."correctCount"::int) as min,

1번 avg(gmr."correctCount"::float) as avg
2번 round(avg(gmr."correctCount"::float),1) as avg

from "GameMathRecord" as gmr

where

  gmr."gameid" = gameidpara and

  gmr."userid" = useridpara and

  gmr."gamedate" >= startdate and

  gmr."gamedate" <enddate

group by

  gmr."gameid",

  gmr."userid"

;

end;

$$ language plpgsql;

by 뉴비디비 [2024.04.12 00:07:26]

pgsql 이면 데이터 타입을 바꿔보세요.

round(avg(gmr."correctCount"::numeric),1) as avg


by knlim [2024.04.12 21:39:05]

의견을 주신대로 numeric으로 처리했는데도 데이터를 못가져 옵니다.

답변 주셔서 감사합니다.

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입