這篇文章主要介紹MySQL實現(xiàn)行轉(zhuǎn)列的方法,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
成都創(chuàng)新互聯(lián)公司是專業(yè)的岫巖網(wǎng)站建設公司,岫巖接單;提供成都網(wǎng)站建設、成都網(wǎng)站制作,網(wǎng)頁設計,網(wǎng)站設計,建網(wǎng)站,PHP網(wǎng)站建設等專業(yè)做網(wǎng)站服務;采用PHP框架,可快速的進行岫巖網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
mysql實現(xiàn)行轉(zhuǎn)列的方法:1、用cross join的方式實現(xiàn),代碼為【cross join(select sum(a.kills) '豬八戒】;2、用case語句的方式實現(xiàn),代碼為【case when user_name='孫悟空'】。
mysql實現(xiàn)行轉(zhuǎn)列的方法:
1、用cross join的方式實現(xiàn)
select * from (select sum(a.kills) '孫悟空' from kills1 as a LEFT JOIN tssrz as b on a.user_id = b.id WHERE b.user_name = '孫悟空' GROUP BY b.user_name) e cross join (select sum(a.kills) '豬八戒' from kills1 as a LEFT JOIN tssrz as b on a.user_id = b.id WHERE b.user_name = '豬八戒' GROUP BY b.user_name) f
2、用case語句的方式實現(xiàn)
SELECT sum(case when user_name='孫悟空' then kills end) as '孫悟空', sum(case when user_name='豬八戒' then kills END) as '豬八戒', sum(case when user_name='沙和尚' then kills END) as '沙和尚' from tssrz as a join kills1 as b on a.id = b.user_id
以上是“mysql實現(xiàn)行轉(zhuǎn)列的方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!