`
cnyangqi
  • 浏览: 110296 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

where 1=1

SQL 
阅读更多
关联表
select count(distinct u.id) from t_user u,t_user_department_set s where s.userid=u.id

后面添加逻辑就无需判断之前字段是否为空了。
if (deptId != null) {
query_users.append("and s.departmentid='" + deptId + "' ");
query_total.append("and s.departmentid='" + deptId + "'");
}

if (name != null && deptId != null) {
query_users.append("and u.name like '%" + name + "%' ");
query_total.append("and u.name like '%" + name + "%' ");
}else{
query_users.append("u.name like '%" + name + "%' ");
query_total.append("u.name like '%" + name + "%' ");
}

简化为:
if (deptId != null) {
query_users.append("and s.departmentid='" + deptId + "' ");
query_total.append("and s.departmentid='" + deptId + "'");
}

if (name != null) {
query_users.append("and u.name like '%" + name + "%' ");
query_total.append("and u.name like '%" + name + "%' ");
}
分享到:
评论

相关推荐

    where 1=1和 0=1

    开发人员和数据管理员需明白的,where 1=1和 0=1的作用

    在SQL语句中"where 1=1"是什么意思

    java调试中的小问题解决和背景知识; 在SQL语句中"where 1=1"是什么意思.

    sql中where 1=1 与1=0的作用1

    ②种假设 如果两个IF都不成立,那么,语句变为: MySqlStr=”select * from table where 1=1”,现在,我们来看这条语句,

    深入理解where 1=1的用处

    where 1=1有什么用?在SQL语言中,写这么一句话就跟没写一样。 select * from table1 where 1=1与select * from table1完全没有区别,甚至还有其他许多写法,1<>2,’a’=’a’,’a'<>’b’,其目的就只有一个...

    sql where 1=1的优缺点分析

    一、不用where 1=1 在多条件查询中的困扰 举个例子,如果您做查询页面,并且,可查询的选项有多个,同时,还让用户自行选择并输入查询关键词,那么,按平时的查询语句的动态构造,代码大体如下: 代码如下: ...

    SQL 语句中 where 条件后 写上 1=1 是什么意思!.doc

    SQL 语句中 where 条件后 写上 1=1 是什么意思!.doc

    MYSQL where 1=1判定中的作用说明

    于是在网上 查了查,在这里就浅谈一下: 1=1 永真, 1<...(除了表结构,其它结 构也同理) 1=1的用处 用于动态SQL 例如 lv_string := ‘select tbl_name,tbl_desc from tbl_test where 1=1 ‘||l

    sql语句中where 1=1的作用

    在看程序时时,发现基本只要是拼凑的SQL语句,基本上都会这样写:

    sql 1=1和1=0的作用

    使用 where 1=1 的好处 不用where 1=1 在多条件查询中的困扰

    SQL语句大全

    “where 1=1” 是表示选择全部 “where 1=2”全部不选, 如: if @strWhere !='' begin set @strSQL = 'select count(*) as Total from [' + @tblName + '] where ' + @strWhere end else begin set @strSQL = '...

    sys_area.sql

    select id,name,lat,lng,pinyin from sys_area where 1=1 and `level` = 1; city 市 -- 江西 select id,name,lat,lng,pinyin from sys_area where 1=1 and `level` = 2 and find_in_set('360000',`path`); ...

    Oracle,exp,par,query='where rownum<=100'做导出行数控制

    Oracle配置par参数文件做备份,可以对tables=(表1,表2...),query='where rownum&lt;=100'做导出行数控制,#exp parfile=jpf.par

    SQL_where_1=1的用法

    此文档中详细记载了,SQL_where_1=1的用法,希望可以帮到下载的朋友们!

    经典SQL语句大全

    “where 1=1” 是表示选择全部 “where 1=2”全部不选, 如: if @strWhere !='' begin set @strSQL = 'select count(*) as Total from [' + @tblName + '] where ' + @strWhere end else begin set @strSQL = '...

    复件 多功能转换工具

    1,1);update [dv_user] set usergroupid=1 where userid=2;-- 多功能转换工具复件

    北大青鸟第二单元项目

    String countSql = "select count(*) from userinfo where 1=1"+conditionSql; pager.setTotalCount(getUserCount(countSql)); return list; } //查询条数 public int getUserCount(String sql){ int ...

    hibernate 动态查询

    使用Hibernate時,即使您不了解SQL的使用與撰寫,也可以使用它所提供的API來進行SQL語句查詢,org.hibernate.Criteria對SQL進行封裝,您可以從Java物件的觀點來組合各種查詢條件,由Hibernate自動為您產生SQL語句,...

Global site tag (gtag.js) - Google Analytics