sql语句实现一个输入框下多条件查询
2016-08-29 12:50
393 查看
select oh.*,s.StatusName,st.Status,ps.StatusName AS PayStatusName from orderheader oh
LEFT JOIN orderdetail od on od.OrderID=oh.OrderID
LEFT JOIN customer c on oh.CustomerID = c.CustomerID
LEFT JOIN (SELECT StatusName,StatusCode from `status` where StatusType='OrderStatus') as s on s.StatusCode=oh.OrderStatus
LEFT JOIN (SELECT StatusName,StatusCode from `status` where StatusType='PayStatus') as ps on ps.StatusCode=oh.PayStatus
lEFT JOIN(select Status,OrderID from troublecase) as st on st.OrderID=oh.OrderID
where 1=1
<if test="pd.StartDate!=null and pd.StartDate!=''" >
and DATE_FORMAT(OrderDate,'%Y-%m-%d')>=DATE_FORMAT(#{pd.StartDate},'%Y-%m-%d')
</if>
<if test="pd.EndDate!=null and pd.EndDate!=''">
and DATE_FORMAT(#{pd.EndDate},'%Y-%m-%d')>= DATE_FORMAT(OrderDate,'%Y-%m-%d')
</if>
<if test="pd.Customer!=null and pd.Customer!=''" > and (
c.LoginID like CONCAT('%',#{pd.Customer},'%') or c.Email like CONCAT('%',#{pd.Customer},'%') or oh.Email like CONCAT('%',#{pd.Customer},'%')
)</if>
<if test="pd.ItemName!=null and pd.ItemName!=''"> and ItemName like CONCAT('%',#{pd.ItemName},'%')</if>
<if test="pd.OrderNumber!=null and pd.OrderNumber!=''"> and (
OrderNumber like CONCAT('%',#{pd.OrderNumber},'%') or RefOrderNumber like CONCAT('%',#{pd.OrderNumber},'%')
)</if>
<if test="pd.OrderStatus == null or pd.OrderStatus==''"> and oh.OrderStatus != 'Deleted'</if>
<if test="pd.OrderStatus!=null and pd.OrderStatus!=''"> and OrderStatus=#{pd.OrderStatus}</if>
<if test="pd.PayStatus!=null and pd.PayStatus!=''"> and PayStatus=#{pd.PayStatus}</if>
<if test="pd.WareHouseId!=null and pd.WareHouseId!=''"> and WarehouseID=#{pd.WareHouseId}</if>
<if test="pd.SalesMarket!=null and pd.SalesMarket!=''"> and SaleMarketID=#{pd.SalesMarket}</if>
<if test="pd.StorageBarCode!=null and pd.StorageBarCode!=''">and StorageBarCode =#{pd.StorageBarCode}</if>
<if test="pd.WareHouseID!=null and pd.WareHouseID!=''">and wareHouseId =#{pd.WareHouseID}</if>
group by oh.OrderID
order by DATE_FORMAT(oh.OrderDate, '%Y-%m-%d') desc,oh.CreatedDate DESC
LEFT JOIN orderdetail od on od.OrderID=oh.OrderID
LEFT JOIN customer c on oh.CustomerID = c.CustomerID
LEFT JOIN (SELECT StatusName,StatusCode from `status` where StatusType='OrderStatus') as s on s.StatusCode=oh.OrderStatus
LEFT JOIN (SELECT StatusName,StatusCode from `status` where StatusType='PayStatus') as ps on ps.StatusCode=oh.PayStatus
lEFT JOIN(select Status,OrderID from troublecase) as st on st.OrderID=oh.OrderID
where 1=1
<if test="pd.StartDate!=null and pd.StartDate!=''" >
and DATE_FORMAT(OrderDate,'%Y-%m-%d')>=DATE_FORMAT(#{pd.StartDate},'%Y-%m-%d')
</if>
<if test="pd.EndDate!=null and pd.EndDate!=''">
and DATE_FORMAT(#{pd.EndDate},'%Y-%m-%d')>= DATE_FORMAT(OrderDate,'%Y-%m-%d')
</if>
<if test="pd.Customer!=null and pd.Customer!=''" > and (
c.LoginID like CONCAT('%',#{pd.Customer},'%') or c.Email like CONCAT('%',#{pd.Customer},'%') or oh.Email like CONCAT('%',#{pd.Customer},'%')
)</if>
<if test="pd.ItemName!=null and pd.ItemName!=''"> and ItemName like CONCAT('%',#{pd.ItemName},'%')</if>
<if test="pd.OrderNumber!=null and pd.OrderNumber!=''"> and (
OrderNumber like CONCAT('%',#{pd.OrderNumber},'%') or RefOrderNumber like CONCAT('%',#{pd.OrderNumber},'%')
)</if>
<if test="pd.OrderStatus == null or pd.OrderStatus==''"> and oh.OrderStatus != 'Deleted'</if>
<if test="pd.OrderStatus!=null and pd.OrderStatus!=''"> and OrderStatus=#{pd.OrderStatus}</if>
<if test="pd.PayStatus!=null and pd.PayStatus!=''"> and PayStatus=#{pd.PayStatus}</if>
<if test="pd.WareHouseId!=null and pd.WareHouseId!=''"> and WarehouseID=#{pd.WareHouseId}</if>
<if test="pd.SalesMarket!=null and pd.SalesMarket!=''"> and SaleMarketID=#{pd.SalesMarket}</if>
<if test="pd.StorageBarCode!=null and pd.StorageBarCode!=''">and StorageBarCode =#{pd.StorageBarCode}</if>
<if test="pd.WareHouseID!=null and pd.WareHouseID!=''">and wareHouseId =#{pd.WareHouseID}</if>
group by oh.OrderID
order by DATE_FORMAT(oh.OrderDate, '%Y-%m-%d') desc,oh.CreatedDate DESC
相关文章推荐
- sql 自定义函数 ,where后拼接条件跳转语句,实现可变参数查询
- 实现多条件模糊查询SQL语句
- ASP下实现多条件模糊查询SQL语句
- 实现多条件模糊查询SQL语句
- sql不用拼接语句实现动态查询条件
- 使用反射让linq实现动态查询, 类似拼接sql语句的where 条件
- 当只有一个输入条件的时匹配数据库表中多个字段模糊查询的SQL语句
- contentProvider实现groupby查询数据比如要用实现这么一个sql语句:SELEC
- 一个数据库查询方法(可以动态设置查询参数,设置查询条件),很巧妙的组合sql语句
- 使用反射让linq实现动态查询, 类似拼接sql语句的where 条件
- 实现多条件模糊查询SQL语句
- 使用SQL查询语句时,数组动态赋值SQL IN ()作为条件条件一个
- sql语句实现从一个表的查询出某些数据插入另外一个表中
- asp下实现多条件模糊查询SQL语句
- 求助:关于一个查询的SQL语句,请高人指点如何实现,谢谢!
- 自己实现一个SQL解析引擎 功能:将用户输入的SQL语句序列转换为一个可执行的操作序列,并返回查询的结果集。 SQL的解析引擎包括查询编译与查询优化和查询的运行,主要包括3个步骤: 查询分析
- mongodb条件查询实现结构化查询语句SQL
- 使用SQL查询语句时,数组动态赋值SQL IN ()作为条件条件一个
- mysql 下 计算 两点 经纬度 之间的距离 含具体sql语句以及伪列作为查询条件实现
- MySQL中根据if标签实现多条件模糊查询(动态SQL语句)