1

我面临一些逻辑问题。希望有人能找到我的解决方案

我有一个查询

select FirstName||'|'||LastName||to_char(salary) 
from (select FirstName,LastName,salary from subs_tbl where salary=24000) 
union all select FirstName||'|'||''||to_char(salary) 
from (select FirstName,LastName,salary from subs_tbl where salary=30000)

所以我的结果将是

Satish|Kumar|24000

Vimal|Kumar|24000

Dinesh||30000

假设我的结果有 3 行,但我需要向整个查询添加另一个条件,即我只需要这些查询组合中的 2 行。

请在这件事上给予我帮助

4

2 回答 2

1
select FirstName||'|'||LastName||to_char(salary) 
from (select FirstName,LastName from subs_tbl where salary=24000) 
union all select FirstName||'|'||''||to_char(salary) 
from (select FirstName,LastName from subs_tbl where salary=30000) limit 0,2
于 2013-02-22T09:51:19.060 回答
1

试试这个避免你用过的工会

SELECT FirstName||'|'||LastName||to_char(salary) 
FROM subs_tbl 
WHERE salary=24000 or salary=30000) 
LIMIT 2

编辑

SELECT fullname
FROM   (SELECT firstname
           || '|'
           || lastname
           || To_char(salary) AS 'FullName'
    FROM   (SELECT firstname,
                   lastname,
                   salary
            FROM   subs_tbl
            WHERE  salary = 24000)
    UNION ALL
    SELECT firstname
           || '|'
           || ''
           || To_char(salary) AS 'FullName'
    FROM   (SELECT firstname,
                   lastname,
                   salary
            FROM   subs_tbl
            WHERE  salary = 30000))
WHERE  rownum <= 5;

希望这可以帮助

于 2013-02-22T09:49:59.957 回答