Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 在Postgres中获得4位小数_Sql_Postgresql - Fatal编程技术网

Sql 在Postgres中获得4位小数

Sql 在Postgres中获得4位小数,sql,postgresql,Sql,Postgresql,我正在尝试运行以下查询: SELECT questionid, (SUM(CASE WHEN correct = FALSE THEN 1 ELSE 0 END)::decimal(10,4) / COUNT(*)::decimal(10,4))::decimal(10,4) AS PercentWrong, COUNT(questionid) AS Questions FROM asmt.testscores WHERE testscoreid IN (SELECT

我正在尝试运行以下查询:

SELECT questionid,
       (SUM(CASE WHEN correct = FALSE THEN 1 ELSE 0 END)::decimal(10,4) / COUNT(*)::decimal(10,4))::decimal(10,4) AS PercentWrong,
       COUNT(questionid) AS Questions
FROM asmt.testscores
WHERE testscoreid IN (SELECT DISTINCT test_score_id
                      FROM ads.fbs_assessment_adaptive_pause_staging)
AND   answered = TRUE
AND   memberid IS NOT NULL
GROUP BY questionid
ORDER BY PercentWrong
我希望列
percenterror
有4位小数,但是上面的查询只给了我2位小数,尽管有
decimal(10,4)
。我也试着使用
real
,但它根本没有给我小数点

如何获取小数点后4位?

尝试使用

试用

SELECT questionid,
       to_char(SUM(CASE WHEN correct = FALSE THEN 1 ELSE 0 END)::float / COUNT(*)::float,'99D9999') AS PercentWrong,
       COUNT(questionid) AS Questions
FROM asmt.testscores
WHERE testscoreid IN (SELECT DISTINCT test_score_id
                      FROM ads.fbs_assessment_adaptive_pause_staging)
AND   answered = TRUE
AND   memberid IS NOT NULL
GROUP BY questionid
ORDER BY PercentWrong