[size=medium][color=red][b]decode(待比较的对象,如果为这个,那么结果为这个,否则结果是这个) [/b][/color][/size]
表issueNew.xml中
字段commandState值:
1代表区级别的领导批示,0代表其他级别的领导的批示,null代表未批示。
字段orgtypeInternalid的值:
1代表区级职能部门上报的事件,0代表其他部门的事件。
[color=blue]
需求 :查出的信息这样排序:先区级领导批示的事件,后区级职能部门上报的事件,最后是普通的事件。[/color]
我写的sql:
select iu.subject, iu.commandState,orgtypeInternalid from issuesnew iu,issuelogsnew il
where il.targeorginternalcode like '1.1.1.1.'||'%' and iu.id=il.issueid and iu.id not in(select issueid from historicalIssues
where orgId=4 or orgInternalCode like '1.1.1.1.'||'%')
order by iu.commandState desc,orgtypeInternalid desc
查询结果如下:
[img]http://dl.iteye.com/upload/attachment/0070/9604/b4b7e201-b614-39e1-bc54-ea072a52303b.jpeg[/img]
[b][color=red][size=large]显然不正确。正确写法如下:[/size][/color][/b]
select iu.subject, iu.commandState,from issuesnew iu,issuelogsnew il
where il.targeorginternalcode like '1.1.1.1.'||'%' and iu.id=il.issueid and iu.id not in(select issueid from historicalIssues
where orgId=4 or orgInternalCode like '1.1.1.1.'||'%')
order by [color=red][b]decode(iu.commandState,null,0,iu.commandState) desc[/b][/color],orgtypeInternalid desc
查询结果如下:
[img]http://dl.iteye.com/upload/attachment/0070/9612/1a7b42b3-2c35-37b2-8eae-f35eb855c45d.jpeg[/img]
表issueNew.xml中
字段commandState值:
1代表区级别的领导批示,0代表其他级别的领导的批示,null代表未批示。
字段orgtypeInternalid的值:
1代表区级职能部门上报的事件,0代表其他部门的事件。
[color=blue]
需求 :查出的信息这样排序:先区级领导批示的事件,后区级职能部门上报的事件,最后是普通的事件。[/color]
我写的sql:
select iu.subject, iu.commandState,orgtypeInternalid from issuesnew iu,issuelogsnew il
where il.targeorginternalcode like '1.1.1.1.'||'%' and iu.id=il.issueid and iu.id not in(select issueid from historicalIssues
where orgId=4 or orgInternalCode like '1.1.1.1.'||'%')
order by iu.commandState desc,orgtypeInternalid desc
查询结果如下:
[img]http://dl.iteye.com/upload/attachment/0070/9604/b4b7e201-b614-39e1-bc54-ea072a52303b.jpeg[/img]
[b][color=red][size=large]显然不正确。正确写法如下:[/size][/color][/b]
select iu.subject, iu.commandState,from issuesnew iu,issuelogsnew il
where il.targeorginternalcode like '1.1.1.1.'||'%' and iu.id=il.issueid and iu.id not in(select issueid from historicalIssues
where orgId=4 or orgInternalCode like '1.1.1.1.'||'%')
order by [color=red][b]decode(iu.commandState,null,0,iu.commandState) desc[/b][/color],orgtypeInternalid desc
查询结果如下:
[img]http://dl.iteye.com/upload/attachment/0070/9612/1a7b42b3-2c35-37b2-8eae-f35eb855c45d.jpeg[/img]