获取所有非空列的计数的查询;
id | Col1 | Col2 | Col3 | Col4 |
--------------------------------
1 | abc | --- | xyz | pqr |
--------------------------------
2 | def | ghi | --- | pqr |
--------------------------------
3 | --- | --- | hgy | --- |
--------------------------------
4 | --- | jko | | uyi |
--------------------------------
SELECT COUNT(*) FROM table 1 WHERE Col1!='---'
SELECT COUNT(*) FROM table 1 WHERE Col2!='---'
SELECT COUNT(*) FROM table 1 WHERE Col3!='---'
在单个查询中
如何得到结果
-----------------------
Cnt1| Cnt2 |Cnt3| Cnt4|
-----------------------
2 | 2 | 2 | 3 |
-----------------------