我正在使用一个查询,该查询在表中搜索两个条件。我举一个例子:
Select *
from Customers
where mobile= '" + textboxt1.Text + "' or Phone = '" + textboxt1.Text + "'
查询返回第一行,其中手机或电话号码与我的textbox1.Text
相等。
我需要设置一个条件:开始查找“整个表”以查找第一个“或”语句(移动)。如果不存在任何结果,则使用第二个或条件(电话)再次搜索整个表。
有什么简单的方法可以编写查询吗?还是我需要为此使用一个保护套?
答案 0 :(得分:3)
假设表中不超过一条记录在# your code, just to store the numbers
n <- vector("numeric",length(V(g)))
names(n) <- V(g)$name
for(i in V(g)$name){
subg <- induced_subgraph(g,
vids = c(which(V(g)$name == i), which(V(g)$rand_attr == "B")))
d <- degree(subg, v = which(V(subg)$name == i))
n[i] <- d
}
n
ID1 ID2 ID3 ID4 ID5 ID6 ID7 ID8
3 2 3 3 1 2 1 3
#names of B vertices
Bvert = vertex.attributes(g)$name[vertex.attributes(g)$rand_attr=="B"]
#number of B vertices connected per vertice
N = sapply(adjacent_vertices(g,1:8),function(i)sum(names(i) %in% Bvert))
N
ID1 ID2 ID3 ID4 ID5 ID6 ID7 ID8
3 2 3 3 1 2 1 3
table(N==n)
上匹配,并且不超过一条记录在mobile
上匹配(考虑到您对用例的描述,这似乎很相关) ,则可以使用phone
和条件排序:
top 1
如果一条记录在select top 1 *
from Customers
where mobile= @textboxt1 or phone = @textboxt2
order by case when mobile= @textboxt1 then 0 else 1 end
上匹配,则条件排序子句将其放在第一位,而mobile
将消除在top 1
上其他(可能)匹配的记录。否则,将保留phone
上的(唯一)匹配记录。
注意:不信任用户输入。始终使用prepared statement and query parameters。我修改了查询,使其使用参数(phone
,@textboxt1
)。
答案 1 :(得分:0)
有时,您可以选择 if (Build.VERSION.SDK_INT >= 19
&& ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
1);
}else{
imageToRoll();
}
@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
imageToRoll();
}
}
}
而不是UNION
来提高性能。
OR