我有两个相似的表,但新的&老了。
table01老
<表类>
id
客户
产品数量 tbody><<tr>001 Cust001 Soap 200 002 Cust002 洗发水 23 003 Cust003 番茄酱 30 表类>
demo
PostgreSQL DISTINCT ON with different ORDER BY
WITH cte AS (
(
SELECT
*
FROM
customer1
ORDER BY
quantity)
UNION ALL (
SELECT
*
FROM
customer2
ORDER BY
quantity))
SELECT DISTINCT ON (id, customer, product)
*
FROM
cte
ORDER BY
1,
2,
3,
4 DESC;
UNION ALL使表中的所有行都在那里,然后在删除重复项时区分,使用ORDER BY来决定哪一行被"保存";