在收集组查询中,如果希望每个子集合只取一张单据,可以使用以下方法:
SELECT customer_id, COUNT(order_id) as order_count
FROM orders
GROUP BY customer_id;
这将返回每个客户的ID和订单数量。
SELECT *
FROM receipts
WHERE receipt_id IN (
SELECT MIN(receipt_id)
FROM receipts
GROUP BY collection_group_id
);
这将返回每个收集组的第一张收据。
SELECT *
FROM (
SELECT *, ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY invoice_date) as row_num
FROM invoices
) AS subquery
WHERE row_num = 1;
这将返回每个客户的第一张发票。
以上是三种常见的方法,可以根据具体的需求选择适合的方法来实现在收集组查询中每个子集合只取一张单据。
领取专属 10元无门槛券
手把手带您无忧上云