如果沒有查詢返回行,我希望能夠返回一行none, none, 0
。我有這樣的SQL:sql - 如果行不存在,則返回一行常量值
select first, last, count(address)
from employee
where last in ('james', 'smith', 'hankers')
group by first, last
union all
select 'none', 'none', 0
from dual
where not exists (select * from employee where last in ('james', 'smith', 'hankers'));
從DB,用於james
和smith
存在的條目,但沒有條目存在hankers
。
但是這個查詢只返回當條目存在時。不返回none, none, 0
。
我在這裏做錯了什麼?
編輯:在這個例子中,我傳遞3個硬編碼值爲last
,但我想知道一個解決方法,如果我們通過getJdbcTemplate傳遞值作爲列表參數,如(:last)
。
你可以使用的行數,喜歡這裏:http://stackoverflow.com/questions/2884996/simple-check-for-select-query-empty-result – aguetat
你用哪個db? – vipin
@vipin Oracle db – qollers