在case语句中使用select

时间:2015-06-04 15:02:52

标签: mysql sql oracle oracle11g oracle10g

我想使用一个允许我得到两个不同结果的查询 取决于过滤。 我试过这个,但它不起作用。

CASE WHEN filtre = 10
THEN
(
 select sum(s.MONTANT_CREANCE_EMP) as creances_emp  , s.ANNEE as annee from sc01_emp s
)
ELSE
(
select sum(s.NOMBRE_CREANCE) as creances_emp  , s.ANNEE as annee from sc01_emp s

)  
END

谢谢大家。

2 个答案:

答案 0 :(得分:0)

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]     

RewriteCond %{REQUEST_URI}  .article.php/tags/([^/]+)$     [NC]
RewriteRule  ^(.*)$      article.php?tag=%1 [L,NC,QSA]

RewriteCond %{REQUEST_URI}  .article.php/([^/]+)$     [NC]
RewriteRule  ^(.*)$      article.php?art=%1 [L,NC,QSA]

RewriteCond %{REQUEST_URI}  .article.php/(.+)$     [NC]
RewriteRule  ^(.*)$      http://domain.com/article/$1 [L,R=301]

答案 1 :(得分:0)

您的代码不符合case expression

的正确语法
select 
CASE 
(select count(*) from dual) WHEN 1 -- this is for test, change it to <filtre> WHEN 10
THEN
(SELECT SUM (MONTANT_CREANCE_EMP) from sc01_emp s) -- if true the result of this subquery will be affected to creances_emp
ELSE
(select SUM (NOMBRE_CREANCE) from sc01_emp s) -- if false the result of this subquery will be affected to creances_emp
END 
as creances_emp,
ANNEE as annee
from sc01_emp s;