【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>