我需要查找SQLite数据库中一列中包含null和not null值的最后3个值的平均值。但是我需要找到只有非空值的平均值。即。如果列包含3,0,4,0,5,0,10我需要平均值为(10 + 5 + 4)/ 3。 任何人都可以帮助我使用我可以使用的查询。我是SQLite的新手。 任何帮助,将不胜感激 谢谢。
答案 0 :(得分:2)
我假设您有一个列to_order
,其中包含您要检索行的订单以及包含您的数字的col
:
select avg(col) from tbl where col is not null order by to_order desc limit 3;
如果您还有其他问题,请发表评论。