我需要爲每一行計算具有空值和非空值的列, 但我不知道如何在PostgreSql中執行此操作。在PostgreSql中計數列爲空並且不爲空
回答
SELECT COUNT(*) as countNullRows FROM yourTable WHERE columnName IS NULL;
SELECT COUNT(*) as countNonNullRows FROM yourTable WHERE columnName IS NOT NULL;
rowName是每列的名稱?? –
對不起,我的錯。我的意思是編寫columnName(編輯答案)...它是你檢查它是否有空值或非空值的列的名稱。 – PetrHejda
但是不止一列,我必須在我的where子句中添加一列每一列? –
你只需要在計數()來指定的列名,它會跳過空:■
select avg(c),count(c) from (select generate_series(1,10) union select null) as a(c);
從後忽略的東西,它只是返回值
列表爲了更清楚:
select
avg(c),
count(c) count_column,
count(*) count_star,
sum(c),
array_agg(c)
from (
select generate_series(1,10) union select null order by 1
) as a(c);
avg | count_column | count_star | sum | array_agg
--------------------+--------------+------------+-----+-----------------------------
5.5000000000000000 | 10 | 11 | 55 | {1,2,3,4,5,6,7,8,9,10,NULL}
(1 row)
如何在此查詢中添加我從表中選擇的內容?我試圖從選擇null更改從表中選擇columnsName,而不是工作。 –
select table count(column_name),avg(column_name)from table_name –
but this「\t select count(column_name),avg(column_name)from table_name」in with union in select generate_series not?我不明白我的選擇表在哪裏輸入。 –
- 1. 處理RedirectStandardOutput爲空並且DataReceivedEventArgs.Data爲空
- 2. C#項目不在列表中,且不爲空或空白
- 3. 不爲空,並且在mysql工作臺中沒有空字符
- 4. 將列設置爲空並加入Postgresql
- 5. 爲什麼我使用strcpy()函數時輸出空並且不爲空?
- 6. 計算列爲空
- 7. Slim 3 getParsedBody()總是爲空並且爲空
- 8. ORACLE顯示計數爲零,當列爲空時爲空
- 9. SSIS不記錄錯誤,而源數據爲空,並且目標列不能爲空使用OLDEDBDestination任務
- 10. SQL Server 2012:檢查列是否爲GUID並且爲空
- 11. 部分數據在java彈簧中爲空並且反應js
- 12. SQL Server創建具有列唯一不爲空且不爲空的表(檢查)
- 13. 爲什麼我的GridViewRow.DataItemIndex不正確並且DataItem爲空?
- 14. Oracle 11g - 優化WHERE不爲NULL並且爲空
- 15. 空數組爲空列表
- 16. $ _FILES爲空並且不包含任何數據
- 17. 設置空數組作爲PostgreSQL中
- 18. django.db.utils.IntegrityError:在列空值 - 但值不爲空
- 19. 如何檢查是否爲空並且不是空SQL Server中的字符串?
- 20. 選擇所有列都有數據且不爲空的記錄
- 21. 如何使計算列不可爲空?
- 22. GROUP BY和計數列是否爲空
- 23. 計數數不爲空 - MS訪問SQL
- 24. 指數爲空列
- 25. Android文件是且不爲空
- 26. SavedInstanceState不爲空,但爲空
- 27. 在sql server 2008中檢查參數爲空或不爲空?
- 28. 計數,如果單元格不爲空
- 29. QBroster爲空,並且SubscriptionListener永遠不會被觸發
- 30. 對象不爲空,並且異常仍然產生
讓你的問題清楚。 – tchelidze
@tchelidze你可以更好地理解? –