像当图片上一列的groupCtrlld的值等于哪个id的值时把对应的id后面的name显示出来
select name from 表名
图上groupCtrlld的值等于id=266 所以两条数据想显示出来的name值都是招待费,想请教sql 怎末写
select a.*, b.name as groupName from 表名 a left join 表名 b on a.groupCtrlld = b.id
查非本行数据用开窗函数
select id,groupCtrlId,
max(case when id=groupCtrlId then name end) over(partition by groupCtrlId)
from t