Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of realizing Row to column in mysql

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the method of mysql to achieve row conversion, the article is very detailed, has a certain reference value, interested friends must read it!

Mysql to achieve row-to-column method: 1, the way to achieve cross join, the code is [cross join (select sum (a.kills) 'Zhu Bajie]; 2, the way to achieve the case statement, the code is [case when user_name=' Sun WuKong'].

The method of transferring rows to columns in mysql:

1. Implement it with cross join.

Select * from (select sum (a.kills) 'Sun WuKong' from kills1 as a LEFT JOIN tssrz as b on a.user_id = b.id WHERE b.user_name = 'Sun WuKong' GROUP BY b.user_name) e cross join (select sum (a.kills) 'Zhu Bajie' from kills1 as a LEFT JOIN tssrz as b on a.user_id = b.id WHERE b.user_name = 'Zhu Bajie' GROUP BY b.user_name) f

2. Implement it with case statement.

SELECT sum (case when user_name=' Sun WuKong 'then kills end) as' Sun WuKong', sum (case when user_name=' Zhu Bajie 'then kills END) as' Zhu Bajie', sum (case when user_name=' Sha Wujing 'then kills END) as' Sha Wujing 'from tssrz as a join kills1 as b on a.id = b.user_id are all the contents of the article "mysql's method of row conversion". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 292

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report