我获得了一个查询语句,该语句找到比较多列的第二低值,并将结果返回到名为' 2nd_lowest'的另一列中。该查询适用于MYSQL。我想在sqlite数据库中得到相同的结果,但sqlite不支持该查询。如何将mysql查询转换为sqlite查询...查询如下:
with num(x) as(
values(1),(2),(3),(4),(5)
),
new as(
select name, case x when 1 then score1 when 2 then score2 when 3 then score3
when 4 then score4 else score5 end val
from test, num
where val!=min(score1,score2,score3,score4,score5)
)
update test set "2nd_lowest"=
(select min(val) from new where new.name=test.name)
我有这个sqlite查询,但我收到异常错误
update test set 2nd_lowest=(select min(val) from "
+ "( select case x when 1 then score1 when 2 then score2 when 3 then score3 when 4 then score4 else score5 end val from test T, "
+ "(select 1 as x union all values (2),(3),(4),(5))X where val!=min(score1,score2,score3,score4,score5)" +
" and T.name=test.name ))
,异常错误是 -
java.sql.SQLException:near"values":syntax error
当我改变'值条款'选择子句,如下例所示:
update test set 2nd_lowest=(select min(val) from "
+ "( select case x when 1 then score1 when 2 then score2 when 3 then score3 when 4 then score4 else score5 end val from test T, "
+ "(select 1 as x union all select (2),(3),(4),(5))X where val!=min(score1,score2,score3,score4,score5)" +
" and T.name=test.name ))<br/>
我得到了这个例外:
Java.sql.SQLException: SELECTs to the left and right of UNION ALL do not have the same number of result columns <br/>
请所有帮助将不胜感激。谢谢。