-5

顧客 ID と購入日を含むテーブルがあり、顧客ごとにグループ化していますが、最初の購入日ではなく最後の購入日を表示したい

私はもう試した

GROUP BY 顧客

ORDER BY 購入日 DESC

4

3 に答える 3

2

実際のクエリを見なくても、次のようなものを使用できる可能性があります。

select t1.customerid, t1.purchasedate, t1.othercol1, t1.othercol2, t1.othercol3
from yourtable t1
inner join
(
    select max(purchasedate) purchasedate, customerid
    from yourtable
    group by customerid
) t2
    on t1.customerid = t2.customerid
    and t1.purchasedate = t2.purchasedate
order by t1.purchasedate desc

max()または、集計関数をpurchasedate列に適用できます

于 2012-10-24T15:20:17.860 に答える
2

どの購入日が必要ですか? 最後の購入日の場合、クエリは次のようになります。

SELECT *, max(purchasedate) FROM table1 GROUP BY customer
于 2012-10-24T15:18:14.317 に答える
2

より適切なサポートを提供するために、実際のクエリとコンテキストを投稿する必要があります。

集計が不足しているようです。これを試すことができます:

SELECT customer, MAX(purchasedate)
FROM sparkles
GROUP BY customer
于 2012-10-24T15:18:37.150 に答える