• 【sql】数据库查询两列合并


    SELECT
        arrival_goods,
        COUNT(1)
    FROM
        goods_info
    WHERE
        Departure_destination IS NOT NULL
    AND Departure_destination != ''
    AND Delivery_num IS NOT NULL
    AND Delivery_num != ''
    GROUP BY
        arrival_goods
    ORDER BY
        arrival_goods
    SELECT DISTINCT
      (
        CONVERT (CHAR(10), t.input_date, 120)
      ) input_date,
      (
        SELECT
          sum(QUANTITY)
        FROM
          PR_BK_HEADER_CARGODYNAMIC a
        WHERE
          CONVERT (CHAR(10), a.input_date, 120) <= t.input_date
          AND a.pr_id = 'OBS0000H5P0XXDE000D'
          AND a.cargo_status_type = 'CargoShipment'
      ) AS quantity
    FROM
      PR_BK_HEADER_CARGODYNAMIC t
    WHERE
      t.pr_id = 'OBS0000H5P0XXDE000D'
      AND t.cargo_status_type = 'CargoShipment'
      AND CONVERT (CHAR(10), t.input_date, 120) <= '2017-10-11'

    错误的:

    SELECT
        DISTINCT t.arrival_goods as xxx,
        (
            SELECT
                COUNT(1)
            FROM
                goods_info a
            WHERE
                a.Departure_destination IS NOT NULL
            AND a.Departure_destination != ''
            AND a.Delivery_num IS NOT NULL
            AND a.Delivery_num != '' 
            GROUP BY
                a.arrival_goods
        ) as yyy
    FROM
        goods_info t
    WHERE
        t.arrival_goods <= '2017-10-11'
    ORDER BY
        t.arrival_goods
  • 相关阅读:
    线上项目部署
    day26 面向对象 单例模式总结
    阿里云服务器,更换操作系统步骤总结
    后端for循环补充
    前端,css
    django-admin 仿写stark组件action,filter筛选过滤,search查询
    7.20晚作业
    用户和群组管理
    7.19 晚作业
    目录和文件管理
  • 原文地址:https://www.cnblogs.com/CESC4/p/7649599.html
Copyright © 2020-2023  润新知