Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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
如何在一列中找到小于postgresql中特定值的总值?_Postgresql - Fatal编程技术网

如何在一列中找到小于postgresql中特定值的总值?

如何在一列中找到小于postgresql中特定值的总值?,postgresql,Postgresql,我有一个类似这样的专栏 Quantity 20 40 10 25 我需要得到该列中小于特定值的值的总数,如 Quantity Value 20 1 40 3 10 0 25 2 使用小于当前值的值将表连接到自身: select a.quantity, count(distinct b.id) from mytable a left join mytable b on b.quantity < a.quanti

我有一个类似这样的专栏

Quantity
20
40
10
25
我需要得到该列中小于特定值的值的总数,如

Quantity    Value
20          1
40          3
10          0
25          2

使用小于当前值的值将表连接到自身:

select a.quantity, count(distinct b.id)
from mytable a
left join mytable b on b.quantity < a.quantity
group by a.quantity
选择countdistinct b.id处理非唯一数量和没有行可连接的最低值,因此连接将返回null,该计数不计算