sql:从行转换为列 [英] sql: convert from row to column
本文介绍了sql:从行转换为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数据库:
Database:
userID Category
1 Apple
2 Apple
2 Orange
3 Apple
3 Apple
预期结果
Expected Result
userID Apple Orange Total
1 1 0 1
2 1 1 2
3 2 0 2
任何想法如何打造Apple和Orange领域?使用什么功能?
any idea how to build the Apple and Orange field? what function to use?
推荐答案
这是经常被问到的问题。请参阅:
MySQL pivot [ ^ ]
pivot tag:MySQL [ ^ ]
It is quite often asked question. Please, see:
MySQL pivot[^]
pivot tag:MySQL[^]
这篇关于sql:从行转换为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文