开发过程中写了一条sql,具体如下
select A.name,A.userid,D.orgname,IFNULL(B.bixiuCount,0),IFNULL(B.xuanxiuCount,0),IFNULL(C.gwBX,0),IFNULL(C.gwXX,0) from
(select person.personid,person.name,users.userid,person.position,person.organizationid
from t_hr_person person LEFT JOIN t_rights_user users on person.personid = users.personid
WHERE person.isdelete=0 and users.isdelete=0) A LEFT JOIN
(select userid,
IFNULL(sum(case when(courseflag=0 ) then 1 else 0 end),0) bixiuCount,
IFNULL(sum(case when(courseflag=1 ) then 1 else 0 end),0) xuanxiuCount
from t_user_course where isdelete=0
GROUP BY userid) B on A.userid = B.userid
LEFT JOIN (
SELECT GWC.dictionaryId dictionaryId,SUM(case WHEN (type=0) THEN 1 else 0 END) gwBX,SUM(case WHEN (type=1) THEN 1 else 0 END) gwXX
FROM t_gwcourse GWC where GWC.isdelete=0
GROUP BY GWC.dictionaryId
) C ON C.dictionaryId=A.position

在开发中尝试创建一个包含子查询的视图时遇到1349错误,该错误提示视图的SELECT语句中不允许有FROM子句的子查询。回顾MySQL创建视图的规则,发现不能包含FROM后的子查询、引用系统或用户变量等。解决办法是将子查询单独创建为视图。此外,文章还提及了MySQL视图在性能上的局限,并提供了一个关于提升视图性能的文章链接。
最低0.47元/天 解锁文章
174万+

被折叠的 条评论
为什么被折叠?



