sdmxyy 2022-05-09 17:18 采纳率: 0%
浏览 12
已结题

子查询读取最外层参数 (关键词-子查询)

子循环读取最外层参数
SELECT
    * 
FROM
    (
    SELECT
        concat(
            ifnull( employee_name, '无' ),
            '/',
            ifnull( c.real_name, '无' ),
            '(',
            ifnull( b.org_title, '无' ),
            ')' 
        ) AS `姓名`,
        (
        SELECT
            IFNULL( ROUND( count( DISTINCT baga.customer_order_id )*(( round( avg( baga.rate ), 2 ))/ 100 ), 2 ), 0 ) 
        FROM
            (
                SELECT
                IF
                    ( @p = user_id, @r := @r + 1, @r := 1 ) AS rank,
                    @p := user_id,
                    x.* 
                FROM
                    ( SELECT @p := NULL, @r := 0 ) r,
                    (
                    SELECT
                        coes.customer_order_id,
                        coes.user_id,
                        coes.employee_id,
                        coes.order_date,
                        coes.score,
                        coes.rate,
                        d.is_first_sales 
                    FROM
                        customer_order_employee_score coes
                        LEFT JOIN customer_order co ON co.id = coes.customer_order_id
                        LEFT JOIN employee e ON e.id = coes.employee_id
                        LEFT JOIN department d ON d.id = e.org_id 
                    WHERE
                        coes.deleted_time IS NULL 
                        AND co.origin_customer_order_id IS NULL 
                        AND coes.user_id 
                        AND co.order_status IN ( 2, 3, 5, 6 ) 
                        AND coes.order_date >= '2010-03-31 00:00:00.000' 
                        AND coes.order_date < '2022-05-01 23:59:59.000' 
                        AND d.is_first_sales = 0 
                        AND coes.employee_id = 94  --这里关联下面的a.id
                    GROUP BY
                        coes.customer_order_id,
                        coes.user_id,
                        coes.employee_id,
                        coes.order_date,
                        d.is_first_sales 
                    ORDER BY
                        user_id,
                        coes.order_date 
                    ) x 
            ) baga 
        WHEREa.id
        baga.employee_id = a.id
      AND
            baga.rank = 1 
            ) AS `一次单数量`,(
        SELECT
            ifnull( sum( sc.score ), 0 ) 
        FROM
            customer_order_employee_score sc
            INNER JOIN customer_order co ON sc.customer_order_id = co.id 
        WHERE
            employee_id = a.id 
            AND order_date >= '2010-03-31 00:00:00.000' 
            AND order_date < '2022-05-01 23:59:59.000' 
            AND sc.deleted_time IS NULL 
        AND co.order_status IN ( 2, 3, 5, 6 )) AS `订单总业绩` 
    FROM
        employee a
        LEFT JOIN department b ON a.org_id = b.id
        LEFT JOIN employee_profile c ON c.employee_id = a.id 
    WHERE
        1 = 1 
        AND (
            a.employee_name IN ( '李江华', 'wuyanmei', 'xiaogu1', 'xiaogu3', 'yzc(二线)' ) 
        OR a.org_id IN ( 0 )) 
        AND b.is_first_sales = 0   --下面的a.id
        AND a.id IN ( SELECT DISTINCT sc.employee_id FROM customer_order_employee_score sc WHERE sc.order_date BETWEEN '2010-03-31 00:00:00.000' AND '2022-05-01 23:59:59.000' ) 
        AND a.deleted_time IS NULL 
    ORDER BY
        `订单总业绩` DESC 
        LIMIT 0,
    10 
    ) tb

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 5月17日
    • 修改了问题 5月10日
    • 修改了问题 5月9日
    • 创建了问题 5月9日

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c