|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
本帖最后由 shunfengfan 于 2011/8/6 17:22 编辑
使用plsql查询出如下结果
想把图中圈中的“财务费用.其他”放在结果的最后面显示出来,怎么写代码呢?
代码如下:
- Select a.Flex_Value, a.Flex_Value_Meaning, a.Description
- From (Select Fls.Flex_Value, Fls.Flex_Value_Meaning, Fls.Description
- From Fnd_Flex_Value_Sets Flv, Fnd_Flex_Values_Vl Fls
- Where Flv.Flex_Value_Set_Id = Fls.Flex_Value_Set_Id
- And Flv.Flex_Value_Set_Name = 'RG_子目段'
- And Sysdate Between Nvl(Fls.Start_Date_Active, Sysdate - 1) And
- Nvl(Fls.End_Date_Active, Sysdate + 1)
- And Fls.Enabled_Flag = 'Y'
- -- And Substr(Fls.Flex_Value, 1, 3) = '004';
- And Fls.Flex_Value In ('00407',
- '00403',
- '00402',
- '00401',
- '00412',
- '00424',
- '00418',
- '00448',
- '00411',
- '00409',
- '00421',
- '00413',
- '00420',
- '00417',
- '00434',
- '00449',
- '00406',
- '00435',
- '00405',
- '00480')
-
- Union All
- Select Null Flex_Value, '1' Flex_Value_Meaning,
- '小计' Description
- From Dual
- Union All
- Select '(科目)' Flex_Value, '2' Flex_Value_Meaning,
- '00000三、财务费用' Description
- From Dual
- Union All
- Select Fls.Flex_Value, Fls.Flex_Value_Meaning, Fls.Description
- From Fnd_Flex_Value_Sets Flv, Fnd_Flex_Values_Vl Fls
- Where Flv.Flex_Value_Set_Id = Fls.Flex_Value_Set_Id
- And Flv.Flex_Value_Set_Name = 'RG_科目段'
- And Sysdate Between Nvl(Fls.Start_Date_Active, Sysdate - 1) And
- Nvl(Fls.End_Date_Active, Sysdate + 1)
- And Fls.Enabled_Flag = 'Y'
- And Fls.Flex_Value In ('550304',
- '55030501',
- '55030506',
- '55030504',
- '55030505',
- '55030502',
- '550301',
- '550302',
- '550306',
- '550303')
-
-
- )a Order By 2;
复制代码 想法1:我刚开始在select中单独使用order by case when,代码如下:
- Select Fls.Flex_Value, Fls.Flex_Value_Meaning, Fls.Description
- From Fnd_Flex_Value_Sets Flv, Fnd_Flex_Values_Vl Fls
- Where Flv.Flex_Value_Set_Id = Fls.Flex_Value_Set_Id
- And Flv.Flex_Value_Set_Name = 'RG_科目段'
- And Sysdate Between Nvl(Fls.Start_Date_Active, Sysdate - 1) And
- Nvl(Fls.End_Date_Active, Sysdate + 1)
- And Fls.Enabled_Flag = 'Y'
- And Fls.Flex_Value In ('550304',
- '55030501',
- '55030506',
- '55030504',
- '55030505',
- '55030502',
- '550301',
- '550302',
- '550306',
- '550303')
- Order By Case
- When Fls.Description = '财务费用.其它' Then
- 1
- Else
- 0
- End
复制代码 这样可以查询出想要的顺序结果,
但是把order by case when放在嵌套的select中却报错:
|
-
|