Get the App
SLTechnology News&Howtos  ›  Database  › 

The method of realizing Row to column in mysql

Shulou Source: shulou.com Published: 2022-06-01 01:54:31 10月02日 Update

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!

Tags: Sun WuKong Zhu Bajie method method code content monk article sentence value interest boy partner more knowledge industry information channel channel reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Linux OPPO Reno Shulou Information Redmi