我到目前为止写的最长的一个SQL语句

本文分享了一个复杂的MySQL SQL查询语句,该查询从多个关联表中提取项目信息,包括项目名称、类别、权限方案等,并对其进行了分组和排序。作者希望通过高手指正,了解这一查询的效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[size=large]这个是我昨天写的一个SQL语句,是mysql的,本身想用程序来写的,最后还是用sql写出来了,小有自豪感。但不知道效率如何,还的请高人指点。[/size]


select na.source_node_id as project_id, p.pname,
(select pc.cname
from projectcategory as pc
where pc.id in (select na_2.sink_node_id
from nodeassociation as na_2
where na_2.sink_node_entity = 'ProjectCategory'
and na_2.source_node_id = na.source_node_id)
) as 'ProjectCategory',

(select ps.name from permissionscheme as ps
where ps.id in (
select na_2.sink_node_id
from nodeassociation as na_2
where na_2.sink_node_entity = 'PermissionScheme'
and na_2.source_node_id = na.source_node_id)
)as 'PermissionScheme',

ra.roletypeparameter,

(select itss.name
from issuetypescreenscheme as itss
where itss.id in (select na_2.sink_node_id
from nodeassociation as na_2
where na_2.sink_node_entity = 'IssueTypeScreenScheme'
and na_2.source_node_id = na.source_node_id)
)as 'IssueTypeScreenScheme'

from nodeassociation as na

join project as p
on na.source_node_id = p.id

join projectroleactor as ra
on na.source_node_id = ra.pid and ra.projectroleid = 10040

group by na.source_node_id
order by na.source_node_id, na.sink_node_entity;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值