且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我的SQL将行转换为列

更新时间:2023-02-06 18:06:08

一般这样的行旋转列称为旋转。但是你在这里指定的与它无关。



你需要一些更复杂的查询:

In general such rotation of rows to columns is called pivoting. But what you specified here has nothing to do with it.

You need a little bit more complex query:
select 
a.id, 
a.firstname, 
a.lastname, 
(select b.typename from table2 b where b.employeeid=a.id and b.typeid=1) as adminname  
(select b.typename from table2 b where b.employeeid=a.id and b.typeid=0) as employeename  
from table1 a