日期:2014-05-18  浏览次数:21079 次

100求sql查询语句
AFunction表:

ARoleFunction表:


我的sql语句:
Assembly code


select a.FunctionCode as 功能代码,FunctionName as 功能名称,
case when b.RoleCode = 'admin'  then 1 else 0 end as Flag 
from AFunction a left join ARoleFunction b on a.FunctionCode=b.FunctionCode
where ModuleName='SysAdmin' 



查询出来的结果是:


多了个A001 FrmA001 0 列..
原因是ARoleFunction表RoleCode列的Admin和XG 他们都有A001.我想得到下面的结果要怎么解决?








------解决方案--------------------
SQL code

select a.FunctionCode as 功能代码,a.FunctionName as 功能名称,
Flag=case when b.RoleCode = 'admin'  then 1 else 0 end
from from AFunction a left join ARoleFunction b on a.FunctionCode=b.FunctionCode and b.RoleCode='admin'
where a.ModuleName='SysAdmin'

------解决方案--------------------
SQL code
select a.FunctionCode as 功能代码,FunctionName as 功能名称,
case when b.RoleCode = 'admin'  then 1 else 0 end as Flag 
from AFunction a left join ARoleFunction b on a.FunctionCode=b.FunctionCode
where ModuleName='SysAdmin' and b.RoleCode='admin'

------解决方案--------------------
SQL code

select a.FunctionCode as 功能代码,FunctionName as 功能名称,case when b.RoleCode = 'admin'  then 1 else 0 end as Flag 
from AFunction a left join ARoleFunction b on a.FunctionCode=b.FunctionCode
where a.ModuleName='SysAdmin' and b.RoleCode='admin' //这句话应该是要加上去的.前面少了一个a.