您好,欢迎访问一九零五行业门户网

SQL查询语句:select * from Table wher A B C D

求一个sql查询语句:select * from table wher a b c d
select   *   from   table   wher   a   and   b   and     c   and   d
其中,a,b,c,d为条件。应该怎样构造啊?
是不是要先判断a,b,c,d中,只要有一个不为空,则“where”
那and呢?》
------解决方案--------------------
判断非空,拼sql字符串.一般先加 where 1=1 ,不会出现where and a了
------解决方案--------------------
hookee() 正解
------解决方案--------------------
hookee() 正解
where 1=1 和 where 1 != 1 在sql中会经常用到
1=1 为后面加东西做好铺垫,1 != 1 得到表的结构
------解决方案--------------------
$awhere[] = 1=1 ;
if(!empty($a))
$awhere[] = $a;
if(!emtpy($b))
$awhere[] = $b;
if(!empty($c))
$awhere[] = $c;
if(!empty($d))
$awhere[] = $d;
$swhere = join( ' and ', $awhere);
$ssql = select * from tbl where $swhere order by id desc ;
------解决方案--------------------
$condition = ;
$link_symbol = ;
if($a)
{
$condition .= $link_symbol $a ;
$link_symbol = and ;
}
依次类推
其它类似信息

推荐信息