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>
order by 对null的处理的更多相关文章
- SQL - Order By如何处理NULL
问题来了.执行SQL语句 SELECT * FROM tbl ORDER BY x, y 如果用来排序的列x.y当中有NULL值,那么它们的顺序是怎样的呢? 不同的数据库有不同的答案,目前的主流数据库 ...
- mysql 变量is null 和 not exists区别
问题: 使用游标遍历时,发现使用 select var into tmp where var=? 然后判断if tmp is null时,不能走完所有的遍历.经debug发现, 当var为空时,则跳出 ...
- MySQL :: MySQL 8.0 Reference Manual :: B.6.4.3 Problems with NULL Values https://dev.mysql.com/doc/refman/8.0/en/problems-with-null.html
MySQL :: MySQL 8.0 Reference Manual :: B.6.4.3 Problems with NULL Values https://dev.mysql.com/doc/r ...
- MySQL为何不建议使用null列
Preface Null is a special constraint of columns.The columns in table will be added null cons ...
- Null / Loopback (Null)
参考: http://www.cnblogs.com/caoguoping100/p/3654452.html https://wiki.wireshark.org/NullLoopback 抓包安装 ...
- NULL-safe equal null 索引 空字符串
小结 1. mysql> INSERT INTO my_table (phone) VALUES (NULL); 有手机号但是不知道 mysql> INSERT INTO my_table ...
- MVC5 网站开发之七 用户功能 2 用户添加和浏览
目录 MVC5网站开发之一 总体概述 MVC5 网站开发之二 创建项目 MVC5 网站开发之三 数据存储层功能实现 MVC5 网站开发之四 业务逻辑层的架构和基本功能 MVC5 网站开发之五 展示层架 ...
- MVC5 网站开发之八 栏目功能 添加、修改和删除
本次实现栏目的浏览.添加.修改和删除. 栏目一共有三种类型. 常规栏目-可以添加子栏目,也可以添加内容模型.当不选择内容模型时,不能添加内容. 单页栏目-栏目只有一个页面,可以设置视图. 链接栏目-栏 ...
- CJCMS系列--持久层对MangoDB的支持
持久层添加对MangoDB数据库的支持 using System; using System.Collections.Generic; using System.Linq; using System. ...
随机推荐
- Exceptions and Errors on iOS
异常:程序缺陷导致:不可恢复:给开发者使用: 错误:资源受限导致:可恢复:提示给用户. https://blog.jayway.com/2010/10/13/exceptions-and-errors ...
- 【转】iOS开发之压缩与解压文件
ziparchive是基于开源代码”MiniZip”的zip压缩与解压的Objective-C 的Class,使用起来非常的简单方法:从http://code.google.com/p/ziparch ...
- SpringMVC+Hibernate框架快速搭建
1. 新建Maven项目springmvc 2. pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" ...
- STM32启动流程
启动文件主要工作: . 设置堆栈指针SP=_initial_sp . 设置PC指针=Reset_Handler . 配置系统时钟 . 配置外部SRAM用于程序变量等数据存储(可选) . 调用C库中的_ ...
- 多GPU设备处理点积示例
多GPU设备处理点积示例,项目打包下载 /* * Copyright 1993-2010 NVIDIA Corporation. All rights reserved. * * NVIDIA Cor ...
- 微信小游戏 demo 飞机大战 代码分析 (三)(spirit.js, animation.js)
微信小游戏 demo 飞机大战 代码分析(三)(spirit.js, animation.js) 微信小游戏 demo 飞机大战 代码分析(一)(main.js) 微信小游戏 demo 飞机大战 代码 ...
- php 获取 今天、昨天、这周、上周、这月、上月、近30天
<?php //今天 $today = date("Y-m-d"); //昨天 $yesterday = date("Y-m-d", strtotime( ...
- 列举Asp.net页面之间传递值的几种方式和优缺点?
一.QueryString变量 优点:使用简单,对于安全性要求不高时传递数字或是文本值非常有效. 缺点:缺乏安全性,由于它的值暴露在浏览器的URL地址中的:不能传递对象. 二. 使用Applicati ...
- vmware 开机自动启动
vmware开机自动启动, 可以使用vmrun命令. 1. 首先在“我的电脑”-“属性”-“高级”-“环境变量”-“PATH”中添加vmware路径,如:C:\Program Files (x86)\ ...
- GTF/GFF