mysql求某个列的前10条记录的总和

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]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值