• order by 对null的处理


    【Oracle 结论】 
    order by colum asc 时,null默认被放在最后
    order by colum desc 时,null默认被放在最前
    nulls first 时,强制null放在最前,不为null的按声明顺序[asc|desc]进行排序
    nulls last 时,强制null放在最后,不为null的按声明顺序[asc|desc]进行排序 
    【MySql 结论】
    order by colum asc 时,null默认被放在最前
    order by colum desc 时,null默认被放在最后
    ORDER BY IF(ISNULL(update_date),0,1) null被强制放在最前,不为null的按声明顺序[asc|desc]进行排序
    ORDER BY IF(ISNULL(update_date),1,0) null被强制放在最后,不为null的按声明顺序[asc|desc]进行排序

    <select id="getPchsOrderReport" parameterClass="java.util.Map" resultClass="com.project.pojo.purchase.SupPurReport">
    		SELECT s.unit_uid as supplierId,s.UNIT_NAME as supplierName,IFNULL(m.orderNum, 0) as orderNum,IFNULL(m.orderPrice, 0) as orderPrice,
    		IFNULL(m.receiveNum, 0) as receiveNum ,IFNULL(m.receivePrice, 0) as receivePrice
    		FROM bas_supplier s LEFT JOIN (
    		SELECT
    			b.supplier_uid AS supplierId,
    			SUM(IFNULL(d.size, 0)) AS orderNum,
    			SUM(IFNULL(d.sum, 0)) AS orderPrice,
    			SUM(IFNULL(d.receive, 0)) AS receiveNum,
    			SUM(
    				IFNULL(d.receive, 0) * IFNULL(d.price, 0)
    			) AS receivePrice
    		FROM 
    		pchs_bill b 
    		LEFT JOIN pchs_detail d ON b.bill_uid = d.bill_uid
    		WHERE b.com_uid = #comUid#
    		<isNotEmpty property="status">
    			and b.status  in <iterate property="status" conjunction="," close=")" open="(">#status[]:Integer#</iterate>
    		</isNotEmpty>
    		<isNotEmpty prepend="AND" property="startDate">
    			<![CDATA[b.bill_date >= #startDate#]]>
    		</isNotEmpty>
    		<isNotEmpty prepend="AND"  property="endDate">
    			<![CDATA[b.bill_date <= #endDate#]]>
    		</isNotEmpty>
    		<isNotEmpty prepend="and" property="storageId"> b.storage_uid = #storageId#  </isNotEmpty>
    		<isNotEmpty prepend=" and b.storage_uid in " property="multi_storage_uid">
    			<iterate property="multi_storage_uid" conjunction="," close=")" open="("> #multi_storage_uid[]# </iterate>
    		</isNotEmpty>
    		GROUP BY
    			b.supplier_uid
    		) m ON m.supplierId=s.unit_uid
    		<isNotEmpty property="supplierId">
    		WHERE s.unit_uid =#supplierId#
    		</isNotEmpty>
    		order by IF(ISNULL(orderNum),1,0),orderNum DESC,IF(ISNULL(orderPrice),1,0),orderPrice DESC
    		<isNotEmpty property="offset"> 
    			LIMIT #offset#,#limit#
    		</isNotEmpty>
    </select>
    

      

  • 相关阅读:
    递归的狂想(菜鸟的胡思乱想)
    关于fiddler的使用总结
    关于mac下 sublime 安装配置java及运行java个人建议
    关于VMwareFusion占用内存过多的问题提几点自己的解决方案
    (ubuntu)ubuntu的root密码设置
    Refactoring to Patterns 学习笔记2 为什么要重构?
    Refactoring to Patterns 学习笔记1 什么是重构?
    [转载]数据结构树之红黑树
    【转载】数据结构之图(存储结构、遍历)
    STL库之单链表:forward_list
  • 原文地址:https://www.cnblogs.com/qiqiweige/p/4933180.html
Copyright © 2020-2023  润新知