-4
A
回答
1
使用CASE
爲其他值返回1爲好,0。爲每列添加總和,並將這些總和相加。
select SUM(case when op1 = 'good' then 1 else 0 end) +
SUM(case when op2 = 'good' then 1 else 0 end) +
SUM(case when op3 = 'good' then 1 else 0 end) +
SUM(case when op4 = 'good' then 1 else 0 end) +
SUM(case when op5 = 'good' then 1 else 0 end) +
SUM(case when op6 = 'good' then 1 else 0 end)
from tablename
或者:
select op, count(*)
from
(
select op1 as op from tablename
union all
select op2 from tablename
union all
select op3 from tablename
union all
select op4 from tablename
union all
select op5 from tablename
union all
select op6 from tablename
) as t
group by op
相關問題
- 1. 從MySQL中的多行獲取總數
- 2. 從多列中獲取一筆總額
- 3. 從數據庫中獲取多列?
- 4. 從多個表中獲取總和
- 5. 如何獲取一行中多行和多列的值?
- 6. mysql如何從多個數據中提取數據並總結
- 7. 如何執行多線程概念從Core數據中獲取多個數據?
- 8. 如何從php多維數組中獲取每一列數據?
- 9. MySQL如何從多個表中獲取多行的總和,然後按總降序對結果進行排序?
- 10. 如何從多維PSafeArray獲取數據?
- 11. 如何從數據庫中選擇多列從用戶在列中獲取列
- 12. 如何從數據庫中獲取多列值光標對象
- 13. 如何從圖像數據類型列中獲取多個值?
- 14. 從多級陣列獲取數據
- 15. 採取類似列的總和從多個數據表
- 16. 如何從mysql查詢中多行的同一列中獲取總值?
- 17. 如何從BigQuery中獲取多個列?
- 18. 如何從數據庫行中獲取多個字段?
- 19. MySQL:獲取多列整數值的數量和總和
- 20. 如何從數據集中的多個表中獲取數據?
- 21. 從Excel中的二維數組中獲取行和列總數
- 22. 如何使用jQuery從多個下拉框中獲取總數?
- 23. 如何獲取數據庫中列的多個數據值?
- 24. 根據行值獲取列的總和
- 25. 如何從數量和價格的平均值中獲得多列總數?
- 26. 獲取SQL中的總多列的
- 27. 從data.table中的列中獲取總數和淨總數R
- 28. 從多維數組中獲取數據
- 29. 獲取多個firebase節點中的數據總和
- 30. 如何獲取mysql中某個表中特定列的總數和總行數
能否請你給我一個例子,請您及時......我沒有在SQL很多知識 – Anna
您應該將表結構改變(ITEM_ID,op_id,得分),那麼SELECT語句變得非常簡單。 – Naktibalda