![](/img/trans.png)
[英]Is it possible to get a true/false answer as to whether a given document matches a previously defined Elasticsearch query?
[英]Mysql query in with the answer true, false
我不久以前学习Java,所以也许我有一个愚蠢的问题。
我有一张桌子,我在那里存储一些信息。 我想在此表中检查某些信息的可用性(仅一行),如果是,请从该行中获取特定列中的信息,如果不行,请执行其他操作。
我真的不知道该怎么做。 我的想法是这样的:首先-检查表:
SELECT * FROM tablename WHERE nickname = "kvant";
然后如果为true,请使用搜索信息进行另一个查询。 并在条件\\ else下执行此操作。 但是我所有的尝试都没有结束。
希望对您有所帮助,对不起我的英语。
检查数据是否存在,如下所示:
IF EXISTS(SELECT * FROM tablename WHERE nickname = "kvant")
BEGIN
--value is found so go ahead
END
ELSE
--value not found
BEGIN
END
一种简单的方法是查询数据库并获取结果。 If result!=Null {//do something} else {//Do something}
(可以使用try - catch
)
纯java可能的解决方案:
尝试在查询中获取该值。 获取该查询的ResultSet rs并:
if(rs.next()) {
String value = rs.getString("value"); //Assuming the column is value and that it is a String.
//Do whatever you want with the value
} else {
//The other thing
}
如果您不能从第一个ResultSet中获取值,请在if中进行另一个查询。
以类似select case exists (select * from yourtable where condition) then 'dothis thing' else 'dootherthing' from 'yourtable' where 'yourcondition'
写在sql中select case exists (select * from yourtable where condition) then 'dothis thing' else 'dootherthing' from 'yourtable' where 'yourcondition'
因为您想知道存在一些条件后就想运行其他查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.