我正面临一些逻辑问题。希望有人能给我找到一个解决方案
我有一个查询
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行。
请帮我处理这个
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
尝试避免使用的联合
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;
希望这能帮助