【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