写SQL时可以考虑的手段:文章来源地址https://www.toymoban.com/news/detail-624161.html
- 行转列
- 先分为多个临时表,然后JOIN到一起
-
select uid, t1.name YuWen, t2.name ShuXue from (select uid, name from tableA where naem = '语文') t1 join (select uid, name from tableA where naem = '数学') t2 on t1.uid = t2.uid;
- 用sum(if())
-
select uid, sum(if(name = '语文')) YuWen, sum(if(name = '数学')) ShuXue from tableA group by uid;
- 列转行
- 先分为多个临时表,然后UNION到一起
-
select uid, YuWen from tableA union all select uid, ShuXue from tableA;
文章来源:https://www.toymoban.com/news/detail-624161.html
到了这里,关于SQL-方法论的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!