mysql求某个列的前10条记录的总和
2016-03-23 14:31
543 查看
mysql求某个列的前10条记录的总和
SELECT ROUND(SUM(a.init_weight), 1) AS thisPageSum FROM ( SELECT t.init_weight, ( SELECT sum(t1.weight) FROM TransportationDelivery t1 WHERE t1.publish_id = t.publish_id AND t. STATUS != '00' AND t1. STATUS != '00' AND t1.platform_id = t.platform_id ) AS trans_weight FROM GoodsOrderM AS t WHERE 1 = 1 AND t. STATUS != '10' AND t.platform_id = ? AND if_can_show = 'Y' AND (t.company_id = ?) AND date_format( create_date, '%Y-%m-%d %H:%i' ) >= ? AND date_format( create_date, '%Y-%m-%d %H:%i' ) <= ? ORDER BY IF (t.appoint_company_id = 0, 0, 1) DESC, IF ( t.docu_type = '1' || t.docu_type = '2', IF ( t.docu_pri_sec = '1', t.publish_id, t.pri_publish_id ), t.publish_id ) DESC, IF ( t.docu_type = '1' || t.docu_type = '2', t.docu_pri_sec *- 1, t.publish_id ) DESC, IF (weight - trans_weight > 0, 1, 0) DESC LIMIT ?, ? ) AS a -- [TJ*YF**0004, 3, 2016-03-23 00:00, 2016-03-23 14:11:12, 0, 10]
求某列的总和
SELECT ROUND(SUM(t.init_weight), 1) AS totalSum, ( SELECT sum(t1.weight) FROM TransportationDelivery t1 WHERE t1.publish_id = t.publish_id AND t. STATUS != '00' AND t1. STATUS != '00' AND t1.platform_id = t.platform_id ) AS trans_weight FROM GoodsOrderM AS t WHERE 1 = 1 AND t. STATUS != '10' AND t.platform_id = ? AND if_can_show = 'Y' AND (t.company_id = ?) AND date_format( create_date, '%Y-%m-%d %H:%i' ) >= ? AND date_format( create_date, '%Y-%m-%d %H:%i' ) <= ? ORDER BY IF (t.appoint_company_id = 0, 0, 1) DESC, IF ( t.docu_type = '1' || t.docu_type = '2', IF ( t.docu_pri_sec = '1', t.publish_id, t.pri_publish_id ), t.publish_id ) DESC, IF ( t.docu_type = '1' || t.docu_type = '2', t.docu_pri_sec *- 1, t.publish_id ) DESC, IF (weight - trans_weight > 0, 1, 0) DESC -- [TJ*YF**0004, 3, 2016-03-23 00:00, 2016-03-23 14:11:12]
相关文章推荐
- 理解MySQL存储过程和函数
- 连接MYSQL的时候报错(找不到请求的.net framework data provider。可能没有安装
- sql按照in中的顺序进行排序 mysql
- mysql数据库设置远程连接权限
- mysql 将多行转换一行
- MySQL数据类型--二进制类型
- MySQL复制过滤参数解释
- mysql-5.5多实例配置
- MySQL数据库binlog日志管理
- MySql同时更新多条记录的方法
- MySQL显示命令
- mysql 命令符操作登陆 展开 查看对象 查看数据表名称 数据表结构 插入
- MySql游标的使用
- mysql事务的提交和回滚和数据引擎有关
- XAMPP打开MySql出现错误
- 简单的mysql 性能和健康程度巡检
- 理解Mysql prepare预处理语句
- 理解MySQL变量和条件
- mysql数据库巡检脚本
- MySQL的Innodb缓存相关优化