hql和ifnull应用两实例
来源:互联网 发布:女孩怀老鼠谣言知乎 编辑:程序博客网 时间:2024/05/21 10:18
hql应用:
public List<Map<String, Object>> getAllVehicleByPlate(String vehiclePlate,String userId,Long companyId) {
String hql = "select new Map(" + "v.simCard as id,v.inNetworkTime as inNetworkTime,"+ " v.plateNumber as text)"
+ " from Vehicle v , Fleet f ,Company c "
+ " where v.fleetId = f.fleetId and v.companyId = c.companyId "
+ " and f.state='0' and c.delFlag='0' and v.plateNumber is not null "
+ " and v.plateNumber!='' and v.state='0' and v.plateNumber like '%"+vehiclePlate+"%'";
if(StringUtils.hasText(userId)){
hql += " and c.manager ='" + userId + "'";
}
if(companyId != null){
hql += " and v.companyId =" + companyId;
}
return this.findByHQL(hql);
}
应用ifnull:
rows_sql =
" select a.news_id as newsId, a.title, a.release_date " +
"as releaseDate, a.state, IFNULL(d.employee_name ,'单位管理员')" +
"AS employeeName" +
" from tb_b_news a, tb_c_system_user c left join tb_c_employee d " +
"on c.employee_id = d.employee_id where a.news_type = '0' " +
"and a.state = "+state+" and a.release_man = c.user_id" +
" and a.release_man = '"+userId+"'";
rows_sql =
" select a.news_id as newsId, a.title, a.release_date " +
"as releaseDate, a.state, IFNULL(d.employee_name ,'单位管理员') as employeeName," +
" (select e.news_sort_name from tb_b_news_sort e " +
"where a.news_sort = e.news_sort_id ) as newsSort" +
" from tb_b_news a, tb_c_system_user c " +
"left join tb_c_employee d on c.employee_id = d.employee_id " +
"where a.news_type = '"+newsType+"' and a.state = "+state+" and a.release_man = c.user_id" +
" and a.release_man = '"+userId+"'";
修改前为以下:
rows_sql =
" select a.news_id as newsId, a.title, a.release_date " +
"as releaseDate, a.state, d.employee_name as employeeName," +
" (select e.news_sort_name from tb_b_news_sort e " +
"where a.news_sort = e.news_sort_id ) as newsSort" +
" from tb_b_news a, tb_c_system_user c " +
"left join tb_c_employee d on c.employee_id = d.employee_id " +
"where a.news_type = '"+newsType+"' and a.state = "+state+" and a.release_man = c.user_id" +
" and a.release_man = '"+userId+"'";
- hql和ifnull应用两实例
- ifnull 和concat函数
- MYSQL IF 和 IFNULL
- hql关联和连接查询实例
- HQL实例
- IFNULL
- sql------isnull 和 ifnull 函数
- IFNULL、NULLIF和ISNULL用法
- hibernate常用的两种查询hql和criteria
- Hibernate分页(sql和hql)两种方法
- android animation的两种应用实例
- 百度地图应用实例两则
- asp.net中购物车的两种存储方式Session和Cookie的应用实例
- asp.net中购物车的两种存储方式Session和Cookie的应用实例
- 关于<%= str%>和<%# str %>两种方式的应用实例
- 购物车的两种存储方式Session和Cookie的应用实例
- HQL语句使用实例
- HQL查询实例
- 不想穷一辈子的人可以看下
- 栈增长方向与大端/小端问题
- 【php输出内容乱码解决方法】
- hdu 1438 hdu1480
- 了解常用的数据库就能了解现在以及未来数据库发展的趋势.1
- hql和ifnull应用两实例
- 九度1078 前序和中序建二叉树
- linux下IPTABLES配置详解
- PHP: Unable to find the wrapper "https"
- 基于datagrid框架的删除、添加与修改
- RAD Studio XE5官方下载地址,破解方法
- 性能测试包括什么测试
- vc2005 使用Boost库的编译步骤.
- C++与Flash的交互