48 个解决方案
#1
大虾们都来帮帮忙啊
#2
写一个存储过程,将所有的条件作为参数(如@case1, @case2...)传入,当某个条件为空的时候,传入Convert.DbNull即可
在存储过程中的SQL语句的Where条件中,以
字段1 = isnull(@case1, 字段1) and 字段2 = isnull(@case2, 字段2) and ...
的形式列出所有条件即可
在存储过程中的SQL语句的Where条件中,以
字段1 = isnull(@case1, 字段1) and 字段2 = isnull(@case2, 字段2) and ...
的形式列出所有条件即可
#3
可以用三元表达式写要简洁些
如:
string name=text_name.Text.trim()=="" ? " and name like '%%' " :" and name like '%"+text_name.Text+"%'";
..
..
..
组织sql语句:
string sql=string.Format("select * from 表名 where 1=1 {0} {1} {2}",name,..,..,..);
如:
string name=text_name.Text.trim()=="" ? " and name like '%%' " :" and name like '%"+text_name.Text+"%'";
..
..
..
组织sql语句:
string sql=string.Format("select * from 表名 where 1=1 {0} {1} {2}",name,..,..,..);
#4
循环/?不懂,up~~
#5
用where 1=1写法, 可以对逻辑条件的判断简化.
以下只是个简单的例子,具体情况,你自己决定
以下只是个简单的例子,具体情况,你自己决定
string sql="select * from tb where 1=1";
string w1;
string w2;
string w3;
if (text1.text!="") w1=" and x1='" + text1.text + "'";
if (text2.text!="") w2=" and x2='" + text2.text + "'";
if (text3.text!="") w3=" and x3='" + text3.text + "'";
sql += w1+w2+w3;
#6
为空的也赋值
#7
没给资料哦,给你一个思路,动态SQL写法
在WHERE 部分匹配
if 条件1==TURE
{ STR=STR +" 匹配条件1";}
if 条件2==TURE
{ STR=STR +" 匹配条件2";}
依次类推
最后把条件部分有SQL部分连接
SQL=SQL+STR
查询这个SQL 就可以了
以上是思路,编写时注意 AND 和STR是否为空判断
在WHERE 部分匹配
if 条件1==TURE
{ STR=STR +" 匹配条件1";}
if 条件2==TURE
{ STR=STR +" 匹配条件2";}
依次类推
最后把条件部分有SQL部分连接
SQL=SQL+STR
查询这个SQL 就可以了
以上是思路,编写时注意 AND 和STR是否为空判断
#8
fcuandy 的方法不赖
#9
如果是存储过程,或带参数的查询语句,确实可以用case when或isnull来处理为空的参数.
比如
http://blog.csdn.net/fcuandy/archive/2007/10/20/1834295.aspx
比如
http://blog.csdn.net/fcuandy/archive/2007/10/20/1834295.aspx
#10
3楼的能不能写的详细点啊 或者在写清楚点 我看的有点蒙 谢谢了
#11
你不会是在一个界面上放了20个文本框,= =;当然你可以For Each一下,然后判断这个textBox的值为不为空,如果不为空,就And XXX like '" & textBox.text & "' "
其实你也可以,把这几个20个条件放到一个DropDownList里,让用户自己去选择,然后添加到DataGrid里。
其实你也可以,把这几个20个条件放到一个DropDownList里,让用户自己去选择,然后添加到DataGrid里。
#12
总之,没有什么循环语句能完成参数的判断 执行查询语句(我实现不了),我就只能通过判断了,
1.在存储过程中判断
2.在程序中判断
1.在存储过程中判断
2.在程序中判断
#13
ArrayList arr = new ArrayList()
arr.Add("条件一");
arr.Add("条件二");
.
.
.
最后用一个循环把里面的值加起来
arr.Add("条件一");
arr.Add("条件二");
.
.
.
最后用一个循环把里面的值加起来
#14
哎 是文本筐就好了 问题是20多个DropDownList 啊
#15
用循环太麻烦了,如果在扩展也不是很方便,个人建议用存储过程拼字符串
如:
@str varchar(500)
set @str=''
set @str=@str+'select * form tablename'
if(@val!='')
set @str=@str+' where colspan='+@val+''
依次类推
如:
@str varchar(500)
set @str=''
set @str=@str+'select * form tablename'
if(@val!='')
set @str=@str+' where colspan='+@val+''
依次类推
#16
用的dropdownlist?
我以前也做过一个这样的
我以前也做过一个这样的
#17
我的有40多个dropdownlist
#18
多谢各位了啊
#19
楼主做的是仿Excel的查询吗?
#20
我在显示中也用 5楼的方法
就是给存储过程或者sql传递 @where条件, 这个条件可以自己按照当前用户设置的条件进行组织,这样比较方便
就是给存储过程或者sql传递 @where条件, 这个条件可以自己按照当前用户设置的条件进行组织,这样比较方便
#21
唉,才 20多个撒
想当年我写的查询控件还是可配置的,都知道要配置多少个
想当年我写的查询控件还是可配置的,都知道要配置多少个
#22
string name=text_name.Text.trim()=="" ? " and name like '%%' " :" and name like '%"+text_name.Text+"%'";
我这里是假设:如有一个输入姓名来进行查询的条件,使用三元表达式来判断输入的表达式text_name.Text.trim()=="" 是否成立。如成立则执行?号后的语句,反之执行 :号后的语句,其它的同理。
组织sql语句时使用了一个技巧 where 1=1 (在没有任何条件的情况下sql语句也不会出错)
string sql=string.Format("select * from 表名 where 1=1 {0} {1} {2}",name,..,..,..);
string.Format()就是拼接字符串啦,自己上网上搜搜就知道啦
#23
呵呵
"SQL语句中巧用WHERE 1=1"
02年还是03的写的贴子,记不太清了, 现在很多人这么用了.
"SQL语句中巧用WHERE 1=1"
02年还是03的写的贴子,记不太清了, 现在很多人这么用了.
#24
发表于:2007-12-24 15:47:5519楼 得分:0
楼主做的是仿Excel的查询吗?
不是的 只是一个查询 Excel的导入导出也要做
楼主做的是仿Excel的查询吗?
不是的 只是一个查询 Excel的导入导出也要做
#25
楼主如果还是没有解决问题的话加我QQ吧,253514915
#26
lz等下结贴,我给你写个,看是你要的不
#27
//columnString 为你所要查询的列,whereString 为所要查询列的值。columnString.count==whereString.count 并且要一一对应
public string getQueryString(List<string> columnString, List<string> whereString)
{
//查询主句
string queryString = "select * from tableName where 1=1";
//循环查询条件所在集合
for(int i=0;i<whereString.Count;i++)
{
//如果查询条件存在,加到主句中
if (!whereString[i].Equals(""))
{
queryString += " and"+columnString[i]+" ='" + whereString[i] + "'";
}//end if
}//end for
//返回查询
return queryString;
}//end method getQueryString
public string getQueryString(List<string> columnString, List<string> whereString)
{
//查询主句
string queryString = "select * from tableName where 1=1";
//循环查询条件所在集合
for(int i=0;i<whereString.Count;i++)
{
//如果查询条件存在,加到主句中
if (!whereString[i].Equals(""))
{
queryString += " and"+columnString[i]+" ='" + whereString[i] + "'";
}//end if
}//end for
//返回查询
return queryString;
}//end method getQueryString
#28
用js遍历吧!
#29
//假设你的表有这个列columnA,columnB,columnC,columnD
//columnString中存的为columnA,columnB,columnC,columnD
//而whereString中存的则是你要查询的条件,如果没有存""。不过位置要对应
//columnString中存的为columnA,columnB,columnC,columnD
//而whereString中存的则是你要查询的条件,如果没有存""。不过位置要对应
#30
匆忙中也没有排版,就将就着看吧~ 对不住了。
看是你要的不?
如果还有问题 请联系~
-----------------------
ps :没测试哈~
看是你要的不?
如果还有问题 请联系~
-----------------------
ps :没测试哈~
#31
阿非正解 ,感觉参数用sortedlist<string ,string> 比较好吧
#32
基本思路 sql="...where 1=1 and "+ 数组或集合类
27楼的方法很好
27楼的方法很好
#33
路过学习学习
#34
俺自己写了个QueryConditionJointer就是干这用滴,
封装一下,用起来很简单!
封装一下,用起来很简单!
#35
LZ 揭贴吧~ 等你发分升级呢~
#36
Mark.好帖,之前也遇到过这种问题,很头疼。
#37
DropDownList和Textbox不是一样的吗?
拼一下条件不就可以了吗?
拼一下条件不就可以了吗?
#38
帮顶
#39
不错,学习了,遇到group by 这些怎么处理呢,
#40
拼接SQL查询语句条件参数。
存储过程传入几个条件参数,一个是where后面的,一个是order by后面的,还有一个是group by后面的,当判断
传入的参数为空时,不加此条件。
条件全部是拼接出来的,最后exec执行拼接出来的SQL语句就行了。
存储过程传入几个条件参数,一个是where后面的,一个是order by后面的,还有一个是group by后面的,当判断
传入的参数为空时,不加此条件。
条件全部是拼接出来的,最后exec执行拼接出来的SQL语句就行了。
#41
判断+组合查询条件
#42
都是与操作吧?写个方法啦:
public void And(ref string condition ,string conditionToAdd)
{
if(condition==null || condition.Length==0){condition = conditionToAdd;return;}
condition += " AND "+conditionToAdd;
}
public void And(ref string condition ,string conditionToAdd)
{
if(condition==null || condition.Length==0){condition = conditionToAdd;return;}
condition += " AND "+conditionToAdd;
}
#43
写一个通用的查询模块,只需要在XML中添加需要查询的字段名即可
#44
刚好我们项目里面有一段这样的代码。
用一个getcondition函数来拼出sql语句,但是得去掉最后多出的一个and。
用一个getcondition函数来拼出sql语句,但是得去掉最后多出的一个and。
#45
string queryString = "select * from tableName where 1=1";
//循环查询条件所在集合
for(int i=0;i <whereString.Count;i++)
{
//如果查询条件存在,加到主句中
if (!whereString[i].Equals(""))
{
queryString += " and"+columnString[i]+" ='" + whereString[i] + "'";
}//end if
}//end for
这个方法很好啊
我之前写的没有这个简洁
//循环查询条件所在集合
for(int i=0;i <whereString.Count;i++)
{
//如果查询条件存在,加到主句中
if (!whereString[i].Equals(""))
{
queryString += " and"+columnString[i]+" ='" + whereString[i] + "'";
}//end if
}//end for
这个方法很好啊
我之前写的没有这个简洁
#46
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strmycon As String = "data source=10.61.224.1;user id=sa;password=sa;database=CYJXXGL ;Asynchronous Processing=true"
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim str4 As String
Dim str5 As String
Dim str6 As String
Dim str7 As String
Dim str8 As String
str1 = DropDownList1.Text
str2 = DropDownList2.Text
str3 = DropDownList3.Text
str4 = DropDownList4.Text
str5 = DropDownList5.Text
str6 = DropDownList6.Text
str7 = TextBox1.Text
str8 = TextBox2.Text
Dim flag As Integer = 0
Dim strmycom As String = " "
Dim strmycom1 As String = " "
Dim strmycom2 As String = " "
Dim strmycom3 As String = " "
strmycom = "select * from VIEW2_htgl_htgl_gg where "
strmycom1 = "select ydsl=sum(ydsl) from VIEW2_htgl_htgl_gg where "
strmycom2 = "select hj=sum(hj) from VIEW2_htgl_htgl_gg where "
strmycom3 = "select count(bh) from VIEW2_htgl_htgl_gg where "
If str1 <> vbNullString Then
strmycom = strmycom & " htbh='" & str1 & "' "
strmycom1 = strmycom1 & " htbh='" & str1 & "' "
strmycom2 = strmycom2 & " htbh='" & str1 & "' "
strmycom3 = strmycom3 & " htbh='" & str1 & "' "
flag = 1
End If
If str2 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and htlx = '" & str2 & "'"
strmycom1 = strmycom1 & " and htlx = '" & str2 & "'"
strmycom2 = strmycom2 & " and htlx = '" & str2 & "'"
strmycom3 = strmycom3 & " and htlx = '" & str2 & "'"
flag = 1
ElseIf str2 <> vbNullString Then
strmycom = strmycom & " htlx = '" & str2 & "'"
strmycom1 = strmycom1 & " htlx = '" & str2 & "'"
strmycom2 = strmycom2 & " htlx = '" & str2 & "'"
strmycom3 = strmycom3 & " htlx = '" & str2 & "'"
flag = 1
End If
If str3 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and dhdw = '" & str3 & "'"
strmycom1 = strmycom1 & " and dhdw = '" & str3 & "'"
strmycom2 = strmycom2 & " and dhdw = '" & str3 & "'"
strmycom3 = strmycom3 & " and dhdw = '" & str3 & "'"
flag = 1
ElseIf str3 <> vbNullString Then
strmycom = strmycom & " dhdw = '" & str3 & "'"
strmycom1 = strmycom1 & " dhdw = '" & str3 & "'"
strmycom2 = strmycom2 & " dhdw = '" & str3 & "'"
strmycom3 = strmycom3 & " dhdw = '" & str3 & "'"
flag = 1
End If
If str4 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and qdr = '" & str4 & "'"
strmycom1 = strmycom1 & " and qdr = '" & str4 & "'"
strmycom2 = strmycom2 & " and qdr = '" & str4 & "'"
strmycom3 = strmycom3 & " and qdr = '" & str4 & "'"
flag = 1
ElseIf str4 <> vbNullString Then
strmycom = strmycom & " qdr = '" & str4 & "'"
strmycom1 = strmycom1 & " qdr = '" & str4 & "'"
strmycom2 = strmycom2 & " qdr = '" & str4 & "'"
strmycom3 = strmycom3 & " qdr = '" & str4 & "'"
flag = 1
End If
If str5 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and cpmc = '" & str5 & "'"
strmycom1 = strmycom1 & " and cpmc = '" & str5 & "'"
strmycom2 = strmycom2 & " and cpmc = '" & str5 & "'"
strmycom3 = strmycom3 & " and cpmc = '" & str5 & "'"
flag = 1
ElseIf str5 <> vbNullString Then
strmycom = strmycom & " cpmc = '" & str5 & "'"
strmycom1 = strmycom1 & " cpmc = '" & str5 & "'"
strmycom2 = strmycom2 & " cpmc = '" & str5 & "'"
strmycom3 = strmycom3 & " cpmc = '" & str5 & "'"
flag = 1
End If
If str6 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and ggxh ='" & str6 & "'"
strmycom1 = strmycom1 & " and ggxh ='" & str6 & "'"
strmycom2 = strmycom2 & " and ggxh ='" & str6 & "'"
strmycom3 = strmycom3 & " and ggxh ='" & str6 & "'"
flag = 1
ElseIf str6 <> vbNullString Then
strmycom = strmycom & " ggxh ='" & str6 & "'"
strmycom1 = strmycom1 & " ggxh ='" & str6 & "'"
strmycom2 = strmycom2 & " ggxh ='" & str6 & "'"
strmycom3 = strmycom3 & " ggxh ='" & str6 & "'"
flag = 1
End If
If str7 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and tbsj >='" & str7 & "'"
strmycom1 = strmycom1 & " and tbsj >='" & str7 & "'"
strmycom2 = strmycom2 & " and tbsj >='" & str7 & "'"
strmycom3 = strmycom3 & " and tbsj >='" & str7 & "'"
flag = 1
Label6.Text = ""
ElseIf str7 <> vbNullString Then
strmycom = strmycom & " tbsj >='" & str7 & "'"
strmycom1 = strmycom1 & " tbsj >='" & str7 & "'"
strmycom2 = strmycom2 & " tbsj >='" & str7 & "'"
strmycom3 = strmycom3 & " tbsj >='" & str7 & "'"
flag = 1
Label6.Text = ""
End If
If str8 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and tbsj <='" & str8 & "'"
strmycom1 = strmycom1 & " and tbsj <='" & str8 & "'"
strmycom2 = strmycom2 & " and tbsj <='" & str8 & "'"
strmycom3 = strmycom3 & " and tbsj <='" & str8 & "'"
flag = 1
Label6.Text = ""
ElseIf str8 <> vbNullString Then
strmycom = strmycom & " tbsj <='" & str8 & "'"
strmycom1 = strmycom1 & " tbsj <='" & str8 & "'"
strmycom2 = strmycom2 & " tbsj <='" & str8 & "'"
strmycom3 = strmycom3 & " tbsj <='" & str8 & "'"
flag = 1
Label6.Text = ""
End If
If flag = 0 Then
strmycom = "select * from VIEW2_htgl_htgl_gg order by htbh asc"
strmycom1 = "select ydsl=sum(ydsl) from VIEW2_htgl_htgl_gg"
strmycom2 = "select hj=sum(hj) from VIEW2_htgl_htgl_gg"
strmycom3 = "select count(bh) from VIEW2_htgl_htgl_gg"
End If
If str7 > str8 Then
Label6.Text = "截止日期不能小于起始日期,请从新输入"
TextBox2.Text = ""
strmycom = ""
End If
这里是8个条件的查询,以次类推.
Dim strmycon As String = "data source=10.61.224.1;user id=sa;password=sa;database=CYJXXGL ;Asynchronous Processing=true"
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim str4 As String
Dim str5 As String
Dim str6 As String
Dim str7 As String
Dim str8 As String
str1 = DropDownList1.Text
str2 = DropDownList2.Text
str3 = DropDownList3.Text
str4 = DropDownList4.Text
str5 = DropDownList5.Text
str6 = DropDownList6.Text
str7 = TextBox1.Text
str8 = TextBox2.Text
Dim flag As Integer = 0
Dim strmycom As String = " "
Dim strmycom1 As String = " "
Dim strmycom2 As String = " "
Dim strmycom3 As String = " "
strmycom = "select * from VIEW2_htgl_htgl_gg where "
strmycom1 = "select ydsl=sum(ydsl) from VIEW2_htgl_htgl_gg where "
strmycom2 = "select hj=sum(hj) from VIEW2_htgl_htgl_gg where "
strmycom3 = "select count(bh) from VIEW2_htgl_htgl_gg where "
If str1 <> vbNullString Then
strmycom = strmycom & " htbh='" & str1 & "' "
strmycom1 = strmycom1 & " htbh='" & str1 & "' "
strmycom2 = strmycom2 & " htbh='" & str1 & "' "
strmycom3 = strmycom3 & " htbh='" & str1 & "' "
flag = 1
End If
If str2 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and htlx = '" & str2 & "'"
strmycom1 = strmycom1 & " and htlx = '" & str2 & "'"
strmycom2 = strmycom2 & " and htlx = '" & str2 & "'"
strmycom3 = strmycom3 & " and htlx = '" & str2 & "'"
flag = 1
ElseIf str2 <> vbNullString Then
strmycom = strmycom & " htlx = '" & str2 & "'"
strmycom1 = strmycom1 & " htlx = '" & str2 & "'"
strmycom2 = strmycom2 & " htlx = '" & str2 & "'"
strmycom3 = strmycom3 & " htlx = '" & str2 & "'"
flag = 1
End If
If str3 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and dhdw = '" & str3 & "'"
strmycom1 = strmycom1 & " and dhdw = '" & str3 & "'"
strmycom2 = strmycom2 & " and dhdw = '" & str3 & "'"
strmycom3 = strmycom3 & " and dhdw = '" & str3 & "'"
flag = 1
ElseIf str3 <> vbNullString Then
strmycom = strmycom & " dhdw = '" & str3 & "'"
strmycom1 = strmycom1 & " dhdw = '" & str3 & "'"
strmycom2 = strmycom2 & " dhdw = '" & str3 & "'"
strmycom3 = strmycom3 & " dhdw = '" & str3 & "'"
flag = 1
End If
If str4 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and qdr = '" & str4 & "'"
strmycom1 = strmycom1 & " and qdr = '" & str4 & "'"
strmycom2 = strmycom2 & " and qdr = '" & str4 & "'"
strmycom3 = strmycom3 & " and qdr = '" & str4 & "'"
flag = 1
ElseIf str4 <> vbNullString Then
strmycom = strmycom & " qdr = '" & str4 & "'"
strmycom1 = strmycom1 & " qdr = '" & str4 & "'"
strmycom2 = strmycom2 & " qdr = '" & str4 & "'"
strmycom3 = strmycom3 & " qdr = '" & str4 & "'"
flag = 1
End If
If str5 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and cpmc = '" & str5 & "'"
strmycom1 = strmycom1 & " and cpmc = '" & str5 & "'"
strmycom2 = strmycom2 & " and cpmc = '" & str5 & "'"
strmycom3 = strmycom3 & " and cpmc = '" & str5 & "'"
flag = 1
ElseIf str5 <> vbNullString Then
strmycom = strmycom & " cpmc = '" & str5 & "'"
strmycom1 = strmycom1 & " cpmc = '" & str5 & "'"
strmycom2 = strmycom2 & " cpmc = '" & str5 & "'"
strmycom3 = strmycom3 & " cpmc = '" & str5 & "'"
flag = 1
End If
If str6 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and ggxh ='" & str6 & "'"
strmycom1 = strmycom1 & " and ggxh ='" & str6 & "'"
strmycom2 = strmycom2 & " and ggxh ='" & str6 & "'"
strmycom3 = strmycom3 & " and ggxh ='" & str6 & "'"
flag = 1
ElseIf str6 <> vbNullString Then
strmycom = strmycom & " ggxh ='" & str6 & "'"
strmycom1 = strmycom1 & " ggxh ='" & str6 & "'"
strmycom2 = strmycom2 & " ggxh ='" & str6 & "'"
strmycom3 = strmycom3 & " ggxh ='" & str6 & "'"
flag = 1
End If
If str7 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and tbsj >='" & str7 & "'"
strmycom1 = strmycom1 & " and tbsj >='" & str7 & "'"
strmycom2 = strmycom2 & " and tbsj >='" & str7 & "'"
strmycom3 = strmycom3 & " and tbsj >='" & str7 & "'"
flag = 1
Label6.Text = ""
ElseIf str7 <> vbNullString Then
strmycom = strmycom & " tbsj >='" & str7 & "'"
strmycom1 = strmycom1 & " tbsj >='" & str7 & "'"
strmycom2 = strmycom2 & " tbsj >='" & str7 & "'"
strmycom3 = strmycom3 & " tbsj >='" & str7 & "'"
flag = 1
Label6.Text = ""
End If
If str8 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and tbsj <='" & str8 & "'"
strmycom1 = strmycom1 & " and tbsj <='" & str8 & "'"
strmycom2 = strmycom2 & " and tbsj <='" & str8 & "'"
strmycom3 = strmycom3 & " and tbsj <='" & str8 & "'"
flag = 1
Label6.Text = ""
ElseIf str8 <> vbNullString Then
strmycom = strmycom & " tbsj <='" & str8 & "'"
strmycom1 = strmycom1 & " tbsj <='" & str8 & "'"
strmycom2 = strmycom2 & " tbsj <='" & str8 & "'"
strmycom3 = strmycom3 & " tbsj <='" & str8 & "'"
flag = 1
Label6.Text = ""
End If
If flag = 0 Then
strmycom = "select * from VIEW2_htgl_htgl_gg order by htbh asc"
strmycom1 = "select ydsl=sum(ydsl) from VIEW2_htgl_htgl_gg"
strmycom2 = "select hj=sum(hj) from VIEW2_htgl_htgl_gg"
strmycom3 = "select count(bh) from VIEW2_htgl_htgl_gg"
End If
If str7 > str8 Then
Label6.Text = "截止日期不能小于起始日期,请从新输入"
TextBox2.Text = ""
strmycom = ""
End If
这里是8个条件的查询,以次类推.
#47
上面那个如何用C#写呀
#48
我多个条件只查一条该怎么办?
#1
大虾们都来帮帮忙啊
#2
写一个存储过程,将所有的条件作为参数(如@case1, @case2...)传入,当某个条件为空的时候,传入Convert.DbNull即可
在存储过程中的SQL语句的Where条件中,以
字段1 = isnull(@case1, 字段1) and 字段2 = isnull(@case2, 字段2) and ...
的形式列出所有条件即可
在存储过程中的SQL语句的Where条件中,以
字段1 = isnull(@case1, 字段1) and 字段2 = isnull(@case2, 字段2) and ...
的形式列出所有条件即可
#3
可以用三元表达式写要简洁些
如:
string name=text_name.Text.trim()=="" ? " and name like '%%' " :" and name like '%"+text_name.Text+"%'";
..
..
..
组织sql语句:
string sql=string.Format("select * from 表名 where 1=1 {0} {1} {2}",name,..,..,..);
如:
string name=text_name.Text.trim()=="" ? " and name like '%%' " :" and name like '%"+text_name.Text+"%'";
..
..
..
组织sql语句:
string sql=string.Format("select * from 表名 where 1=1 {0} {1} {2}",name,..,..,..);
#4
循环/?不懂,up~~
#5
用where 1=1写法, 可以对逻辑条件的判断简化.
以下只是个简单的例子,具体情况,你自己决定
以下只是个简单的例子,具体情况,你自己决定
string sql="select * from tb where 1=1";
string w1;
string w2;
string w3;
if (text1.text!="") w1=" and x1='" + text1.text + "'";
if (text2.text!="") w2=" and x2='" + text2.text + "'";
if (text3.text!="") w3=" and x3='" + text3.text + "'";
sql += w1+w2+w3;
#6
为空的也赋值
#7
没给资料哦,给你一个思路,动态SQL写法
在WHERE 部分匹配
if 条件1==TURE
{ STR=STR +" 匹配条件1";}
if 条件2==TURE
{ STR=STR +" 匹配条件2";}
依次类推
最后把条件部分有SQL部分连接
SQL=SQL+STR
查询这个SQL 就可以了
以上是思路,编写时注意 AND 和STR是否为空判断
在WHERE 部分匹配
if 条件1==TURE
{ STR=STR +" 匹配条件1";}
if 条件2==TURE
{ STR=STR +" 匹配条件2";}
依次类推
最后把条件部分有SQL部分连接
SQL=SQL+STR
查询这个SQL 就可以了
以上是思路,编写时注意 AND 和STR是否为空判断
#8
fcuandy 的方法不赖
#9
如果是存储过程,或带参数的查询语句,确实可以用case when或isnull来处理为空的参数.
比如
http://blog.csdn.net/fcuandy/archive/2007/10/20/1834295.aspx
比如
http://blog.csdn.net/fcuandy/archive/2007/10/20/1834295.aspx
#10
3楼的能不能写的详细点啊 或者在写清楚点 我看的有点蒙 谢谢了
#11
你不会是在一个界面上放了20个文本框,= =;当然你可以For Each一下,然后判断这个textBox的值为不为空,如果不为空,就And XXX like '" & textBox.text & "' "
其实你也可以,把这几个20个条件放到一个DropDownList里,让用户自己去选择,然后添加到DataGrid里。
其实你也可以,把这几个20个条件放到一个DropDownList里,让用户自己去选择,然后添加到DataGrid里。
#12
总之,没有什么循环语句能完成参数的判断 执行查询语句(我实现不了),我就只能通过判断了,
1.在存储过程中判断
2.在程序中判断
1.在存储过程中判断
2.在程序中判断
#13
ArrayList arr = new ArrayList()
arr.Add("条件一");
arr.Add("条件二");
.
.
.
最后用一个循环把里面的值加起来
arr.Add("条件一");
arr.Add("条件二");
.
.
.
最后用一个循环把里面的值加起来
#14
哎 是文本筐就好了 问题是20多个DropDownList 啊
#15
用循环太麻烦了,如果在扩展也不是很方便,个人建议用存储过程拼字符串
如:
@str varchar(500)
set @str=''
set @str=@str+'select * form tablename'
if(@val!='')
set @str=@str+' where colspan='+@val+''
依次类推
如:
@str varchar(500)
set @str=''
set @str=@str+'select * form tablename'
if(@val!='')
set @str=@str+' where colspan='+@val+''
依次类推
#16
用的dropdownlist?
我以前也做过一个这样的
我以前也做过一个这样的
#17
我的有40多个dropdownlist
#18
多谢各位了啊
#19
楼主做的是仿Excel的查询吗?
#20
我在显示中也用 5楼的方法
就是给存储过程或者sql传递 @where条件, 这个条件可以自己按照当前用户设置的条件进行组织,这样比较方便
就是给存储过程或者sql传递 @where条件, 这个条件可以自己按照当前用户设置的条件进行组织,这样比较方便
#21
唉,才 20多个撒
想当年我写的查询控件还是可配置的,都知道要配置多少个
想当年我写的查询控件还是可配置的,都知道要配置多少个
#22
string name=text_name.Text.trim()=="" ? " and name like '%%' " :" and name like '%"+text_name.Text+"%'";
我这里是假设:如有一个输入姓名来进行查询的条件,使用三元表达式来判断输入的表达式text_name.Text.trim()=="" 是否成立。如成立则执行?号后的语句,反之执行 :号后的语句,其它的同理。
组织sql语句时使用了一个技巧 where 1=1 (在没有任何条件的情况下sql语句也不会出错)
string sql=string.Format("select * from 表名 where 1=1 {0} {1} {2}",name,..,..,..);
string.Format()就是拼接字符串啦,自己上网上搜搜就知道啦
#23
呵呵
"SQL语句中巧用WHERE 1=1"
02年还是03的写的贴子,记不太清了, 现在很多人这么用了.
"SQL语句中巧用WHERE 1=1"
02年还是03的写的贴子,记不太清了, 现在很多人这么用了.
#24
发表于:2007-12-24 15:47:5519楼 得分:0
楼主做的是仿Excel的查询吗?
不是的 只是一个查询 Excel的导入导出也要做
楼主做的是仿Excel的查询吗?
不是的 只是一个查询 Excel的导入导出也要做
#25
楼主如果还是没有解决问题的话加我QQ吧,253514915
#26
lz等下结贴,我给你写个,看是你要的不
#27
//columnString 为你所要查询的列,whereString 为所要查询列的值。columnString.count==whereString.count 并且要一一对应
public string getQueryString(List<string> columnString, List<string> whereString)
{
//查询主句
string queryString = "select * from tableName where 1=1";
//循环查询条件所在集合
for(int i=0;i<whereString.Count;i++)
{
//如果查询条件存在,加到主句中
if (!whereString[i].Equals(""))
{
queryString += " and"+columnString[i]+" ='" + whereString[i] + "'";
}//end if
}//end for
//返回查询
return queryString;
}//end method getQueryString
public string getQueryString(List<string> columnString, List<string> whereString)
{
//查询主句
string queryString = "select * from tableName where 1=1";
//循环查询条件所在集合
for(int i=0;i<whereString.Count;i++)
{
//如果查询条件存在,加到主句中
if (!whereString[i].Equals(""))
{
queryString += " and"+columnString[i]+" ='" + whereString[i] + "'";
}//end if
}//end for
//返回查询
return queryString;
}//end method getQueryString
#28
用js遍历吧!
#29
//假设你的表有这个列columnA,columnB,columnC,columnD
//columnString中存的为columnA,columnB,columnC,columnD
//而whereString中存的则是你要查询的条件,如果没有存""。不过位置要对应
//columnString中存的为columnA,columnB,columnC,columnD
//而whereString中存的则是你要查询的条件,如果没有存""。不过位置要对应
#30
匆忙中也没有排版,就将就着看吧~ 对不住了。
看是你要的不?
如果还有问题 请联系~
-----------------------
ps :没测试哈~
看是你要的不?
如果还有问题 请联系~
-----------------------
ps :没测试哈~
#31
阿非正解 ,感觉参数用sortedlist<string ,string> 比较好吧
#32
基本思路 sql="...where 1=1 and "+ 数组或集合类
27楼的方法很好
27楼的方法很好
#33
路过学习学习
#34
俺自己写了个QueryConditionJointer就是干这用滴,
封装一下,用起来很简单!
封装一下,用起来很简单!
#35
LZ 揭贴吧~ 等你发分升级呢~
#36
Mark.好帖,之前也遇到过这种问题,很头疼。
#37
DropDownList和Textbox不是一样的吗?
拼一下条件不就可以了吗?
拼一下条件不就可以了吗?
#38
帮顶
#39
不错,学习了,遇到group by 这些怎么处理呢,
#40
拼接SQL查询语句条件参数。
存储过程传入几个条件参数,一个是where后面的,一个是order by后面的,还有一个是group by后面的,当判断
传入的参数为空时,不加此条件。
条件全部是拼接出来的,最后exec执行拼接出来的SQL语句就行了。
存储过程传入几个条件参数,一个是where后面的,一个是order by后面的,还有一个是group by后面的,当判断
传入的参数为空时,不加此条件。
条件全部是拼接出来的,最后exec执行拼接出来的SQL语句就行了。
#41
判断+组合查询条件
#42
都是与操作吧?写个方法啦:
public void And(ref string condition ,string conditionToAdd)
{
if(condition==null || condition.Length==0){condition = conditionToAdd;return;}
condition += " AND "+conditionToAdd;
}
public void And(ref string condition ,string conditionToAdd)
{
if(condition==null || condition.Length==0){condition = conditionToAdd;return;}
condition += " AND "+conditionToAdd;
}
#43
写一个通用的查询模块,只需要在XML中添加需要查询的字段名即可
#44
刚好我们项目里面有一段这样的代码。
用一个getcondition函数来拼出sql语句,但是得去掉最后多出的一个and。
用一个getcondition函数来拼出sql语句,但是得去掉最后多出的一个and。
#45
string queryString = "select * from tableName where 1=1";
//循环查询条件所在集合
for(int i=0;i <whereString.Count;i++)
{
//如果查询条件存在,加到主句中
if (!whereString[i].Equals(""))
{
queryString += " and"+columnString[i]+" ='" + whereString[i] + "'";
}//end if
}//end for
这个方法很好啊
我之前写的没有这个简洁
//循环查询条件所在集合
for(int i=0;i <whereString.Count;i++)
{
//如果查询条件存在,加到主句中
if (!whereString[i].Equals(""))
{
queryString += " and"+columnString[i]+" ='" + whereString[i] + "'";
}//end if
}//end for
这个方法很好啊
我之前写的没有这个简洁
#46
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strmycon As String = "data source=10.61.224.1;user id=sa;password=sa;database=CYJXXGL ;Asynchronous Processing=true"
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim str4 As String
Dim str5 As String
Dim str6 As String
Dim str7 As String
Dim str8 As String
str1 = DropDownList1.Text
str2 = DropDownList2.Text
str3 = DropDownList3.Text
str4 = DropDownList4.Text
str5 = DropDownList5.Text
str6 = DropDownList6.Text
str7 = TextBox1.Text
str8 = TextBox2.Text
Dim flag As Integer = 0
Dim strmycom As String = " "
Dim strmycom1 As String = " "
Dim strmycom2 As String = " "
Dim strmycom3 As String = " "
strmycom = "select * from VIEW2_htgl_htgl_gg where "
strmycom1 = "select ydsl=sum(ydsl) from VIEW2_htgl_htgl_gg where "
strmycom2 = "select hj=sum(hj) from VIEW2_htgl_htgl_gg where "
strmycom3 = "select count(bh) from VIEW2_htgl_htgl_gg where "
If str1 <> vbNullString Then
strmycom = strmycom & " htbh='" & str1 & "' "
strmycom1 = strmycom1 & " htbh='" & str1 & "' "
strmycom2 = strmycom2 & " htbh='" & str1 & "' "
strmycom3 = strmycom3 & " htbh='" & str1 & "' "
flag = 1
End If
If str2 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and htlx = '" & str2 & "'"
strmycom1 = strmycom1 & " and htlx = '" & str2 & "'"
strmycom2 = strmycom2 & " and htlx = '" & str2 & "'"
strmycom3 = strmycom3 & " and htlx = '" & str2 & "'"
flag = 1
ElseIf str2 <> vbNullString Then
strmycom = strmycom & " htlx = '" & str2 & "'"
strmycom1 = strmycom1 & " htlx = '" & str2 & "'"
strmycom2 = strmycom2 & " htlx = '" & str2 & "'"
strmycom3 = strmycom3 & " htlx = '" & str2 & "'"
flag = 1
End If
If str3 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and dhdw = '" & str3 & "'"
strmycom1 = strmycom1 & " and dhdw = '" & str3 & "'"
strmycom2 = strmycom2 & " and dhdw = '" & str3 & "'"
strmycom3 = strmycom3 & " and dhdw = '" & str3 & "'"
flag = 1
ElseIf str3 <> vbNullString Then
strmycom = strmycom & " dhdw = '" & str3 & "'"
strmycom1 = strmycom1 & " dhdw = '" & str3 & "'"
strmycom2 = strmycom2 & " dhdw = '" & str3 & "'"
strmycom3 = strmycom3 & " dhdw = '" & str3 & "'"
flag = 1
End If
If str4 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and qdr = '" & str4 & "'"
strmycom1 = strmycom1 & " and qdr = '" & str4 & "'"
strmycom2 = strmycom2 & " and qdr = '" & str4 & "'"
strmycom3 = strmycom3 & " and qdr = '" & str4 & "'"
flag = 1
ElseIf str4 <> vbNullString Then
strmycom = strmycom & " qdr = '" & str4 & "'"
strmycom1 = strmycom1 & " qdr = '" & str4 & "'"
strmycom2 = strmycom2 & " qdr = '" & str4 & "'"
strmycom3 = strmycom3 & " qdr = '" & str4 & "'"
flag = 1
End If
If str5 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and cpmc = '" & str5 & "'"
strmycom1 = strmycom1 & " and cpmc = '" & str5 & "'"
strmycom2 = strmycom2 & " and cpmc = '" & str5 & "'"
strmycom3 = strmycom3 & " and cpmc = '" & str5 & "'"
flag = 1
ElseIf str5 <> vbNullString Then
strmycom = strmycom & " cpmc = '" & str5 & "'"
strmycom1 = strmycom1 & " cpmc = '" & str5 & "'"
strmycom2 = strmycom2 & " cpmc = '" & str5 & "'"
strmycom3 = strmycom3 & " cpmc = '" & str5 & "'"
flag = 1
End If
If str6 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and ggxh ='" & str6 & "'"
strmycom1 = strmycom1 & " and ggxh ='" & str6 & "'"
strmycom2 = strmycom2 & " and ggxh ='" & str6 & "'"
strmycom3 = strmycom3 & " and ggxh ='" & str6 & "'"
flag = 1
ElseIf str6 <> vbNullString Then
strmycom = strmycom & " ggxh ='" & str6 & "'"
strmycom1 = strmycom1 & " ggxh ='" & str6 & "'"
strmycom2 = strmycom2 & " ggxh ='" & str6 & "'"
strmycom3 = strmycom3 & " ggxh ='" & str6 & "'"
flag = 1
End If
If str7 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and tbsj >='" & str7 & "'"
strmycom1 = strmycom1 & " and tbsj >='" & str7 & "'"
strmycom2 = strmycom2 & " and tbsj >='" & str7 & "'"
strmycom3 = strmycom3 & " and tbsj >='" & str7 & "'"
flag = 1
Label6.Text = ""
ElseIf str7 <> vbNullString Then
strmycom = strmycom & " tbsj >='" & str7 & "'"
strmycom1 = strmycom1 & " tbsj >='" & str7 & "'"
strmycom2 = strmycom2 & " tbsj >='" & str7 & "'"
strmycom3 = strmycom3 & " tbsj >='" & str7 & "'"
flag = 1
Label6.Text = ""
End If
If str8 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and tbsj <='" & str8 & "'"
strmycom1 = strmycom1 & " and tbsj <='" & str8 & "'"
strmycom2 = strmycom2 & " and tbsj <='" & str8 & "'"
strmycom3 = strmycom3 & " and tbsj <='" & str8 & "'"
flag = 1
Label6.Text = ""
ElseIf str8 <> vbNullString Then
strmycom = strmycom & " tbsj <='" & str8 & "'"
strmycom1 = strmycom1 & " tbsj <='" & str8 & "'"
strmycom2 = strmycom2 & " tbsj <='" & str8 & "'"
strmycom3 = strmycom3 & " tbsj <='" & str8 & "'"
flag = 1
Label6.Text = ""
End If
If flag = 0 Then
strmycom = "select * from VIEW2_htgl_htgl_gg order by htbh asc"
strmycom1 = "select ydsl=sum(ydsl) from VIEW2_htgl_htgl_gg"
strmycom2 = "select hj=sum(hj) from VIEW2_htgl_htgl_gg"
strmycom3 = "select count(bh) from VIEW2_htgl_htgl_gg"
End If
If str7 > str8 Then
Label6.Text = "截止日期不能小于起始日期,请从新输入"
TextBox2.Text = ""
strmycom = ""
End If
这里是8个条件的查询,以次类推.
Dim strmycon As String = "data source=10.61.224.1;user id=sa;password=sa;database=CYJXXGL ;Asynchronous Processing=true"
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim str4 As String
Dim str5 As String
Dim str6 As String
Dim str7 As String
Dim str8 As String
str1 = DropDownList1.Text
str2 = DropDownList2.Text
str3 = DropDownList3.Text
str4 = DropDownList4.Text
str5 = DropDownList5.Text
str6 = DropDownList6.Text
str7 = TextBox1.Text
str8 = TextBox2.Text
Dim flag As Integer = 0
Dim strmycom As String = " "
Dim strmycom1 As String = " "
Dim strmycom2 As String = " "
Dim strmycom3 As String = " "
strmycom = "select * from VIEW2_htgl_htgl_gg where "
strmycom1 = "select ydsl=sum(ydsl) from VIEW2_htgl_htgl_gg where "
strmycom2 = "select hj=sum(hj) from VIEW2_htgl_htgl_gg where "
strmycom3 = "select count(bh) from VIEW2_htgl_htgl_gg where "
If str1 <> vbNullString Then
strmycom = strmycom & " htbh='" & str1 & "' "
strmycom1 = strmycom1 & " htbh='" & str1 & "' "
strmycom2 = strmycom2 & " htbh='" & str1 & "' "
strmycom3 = strmycom3 & " htbh='" & str1 & "' "
flag = 1
End If
If str2 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and htlx = '" & str2 & "'"
strmycom1 = strmycom1 & " and htlx = '" & str2 & "'"
strmycom2 = strmycom2 & " and htlx = '" & str2 & "'"
strmycom3 = strmycom3 & " and htlx = '" & str2 & "'"
flag = 1
ElseIf str2 <> vbNullString Then
strmycom = strmycom & " htlx = '" & str2 & "'"
strmycom1 = strmycom1 & " htlx = '" & str2 & "'"
strmycom2 = strmycom2 & " htlx = '" & str2 & "'"
strmycom3 = strmycom3 & " htlx = '" & str2 & "'"
flag = 1
End If
If str3 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and dhdw = '" & str3 & "'"
strmycom1 = strmycom1 & " and dhdw = '" & str3 & "'"
strmycom2 = strmycom2 & " and dhdw = '" & str3 & "'"
strmycom3 = strmycom3 & " and dhdw = '" & str3 & "'"
flag = 1
ElseIf str3 <> vbNullString Then
strmycom = strmycom & " dhdw = '" & str3 & "'"
strmycom1 = strmycom1 & " dhdw = '" & str3 & "'"
strmycom2 = strmycom2 & " dhdw = '" & str3 & "'"
strmycom3 = strmycom3 & " dhdw = '" & str3 & "'"
flag = 1
End If
If str4 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and qdr = '" & str4 & "'"
strmycom1 = strmycom1 & " and qdr = '" & str4 & "'"
strmycom2 = strmycom2 & " and qdr = '" & str4 & "'"
strmycom3 = strmycom3 & " and qdr = '" & str4 & "'"
flag = 1
ElseIf str4 <> vbNullString Then
strmycom = strmycom & " qdr = '" & str4 & "'"
strmycom1 = strmycom1 & " qdr = '" & str4 & "'"
strmycom2 = strmycom2 & " qdr = '" & str4 & "'"
strmycom3 = strmycom3 & " qdr = '" & str4 & "'"
flag = 1
End If
If str5 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and cpmc = '" & str5 & "'"
strmycom1 = strmycom1 & " and cpmc = '" & str5 & "'"
strmycom2 = strmycom2 & " and cpmc = '" & str5 & "'"
strmycom3 = strmycom3 & " and cpmc = '" & str5 & "'"
flag = 1
ElseIf str5 <> vbNullString Then
strmycom = strmycom & " cpmc = '" & str5 & "'"
strmycom1 = strmycom1 & " cpmc = '" & str5 & "'"
strmycom2 = strmycom2 & " cpmc = '" & str5 & "'"
strmycom3 = strmycom3 & " cpmc = '" & str5 & "'"
flag = 1
End If
If str6 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and ggxh ='" & str6 & "'"
strmycom1 = strmycom1 & " and ggxh ='" & str6 & "'"
strmycom2 = strmycom2 & " and ggxh ='" & str6 & "'"
strmycom3 = strmycom3 & " and ggxh ='" & str6 & "'"
flag = 1
ElseIf str6 <> vbNullString Then
strmycom = strmycom & " ggxh ='" & str6 & "'"
strmycom1 = strmycom1 & " ggxh ='" & str6 & "'"
strmycom2 = strmycom2 & " ggxh ='" & str6 & "'"
strmycom3 = strmycom3 & " ggxh ='" & str6 & "'"
flag = 1
End If
If str7 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and tbsj >='" & str7 & "'"
strmycom1 = strmycom1 & " and tbsj >='" & str7 & "'"
strmycom2 = strmycom2 & " and tbsj >='" & str7 & "'"
strmycom3 = strmycom3 & " and tbsj >='" & str7 & "'"
flag = 1
Label6.Text = ""
ElseIf str7 <> vbNullString Then
strmycom = strmycom & " tbsj >='" & str7 & "'"
strmycom1 = strmycom1 & " tbsj >='" & str7 & "'"
strmycom2 = strmycom2 & " tbsj >='" & str7 & "'"
strmycom3 = strmycom3 & " tbsj >='" & str7 & "'"
flag = 1
Label6.Text = ""
End If
If str8 <> vbNullString And flag = 1 Then
strmycom = strmycom & " and tbsj <='" & str8 & "'"
strmycom1 = strmycom1 & " and tbsj <='" & str8 & "'"
strmycom2 = strmycom2 & " and tbsj <='" & str8 & "'"
strmycom3 = strmycom3 & " and tbsj <='" & str8 & "'"
flag = 1
Label6.Text = ""
ElseIf str8 <> vbNullString Then
strmycom = strmycom & " tbsj <='" & str8 & "'"
strmycom1 = strmycom1 & " tbsj <='" & str8 & "'"
strmycom2 = strmycom2 & " tbsj <='" & str8 & "'"
strmycom3 = strmycom3 & " tbsj <='" & str8 & "'"
flag = 1
Label6.Text = ""
End If
If flag = 0 Then
strmycom = "select * from VIEW2_htgl_htgl_gg order by htbh asc"
strmycom1 = "select ydsl=sum(ydsl) from VIEW2_htgl_htgl_gg"
strmycom2 = "select hj=sum(hj) from VIEW2_htgl_htgl_gg"
strmycom3 = "select count(bh) from VIEW2_htgl_htgl_gg"
End If
If str7 > str8 Then
Label6.Text = "截止日期不能小于起始日期,请从新输入"
TextBox2.Text = ""
strmycom = ""
End If
这里是8个条件的查询,以次类推.
#47
上面那个如何用C#写呀
#48
我多个条件只查一条该怎么办?