私は次のテーブルを持っています
次のクエリを使用したところ、エラー メッセージが表示されました。エラーの原因は特定できますが、どうすれば解決できますか
select min(id),customer_id,created_at from thunderbolt_orders
group by customer_id
最小 ID の customer_id と created_at が必要ですが、どうすれば達成できますか。
私は次のテーブルを持っています
次のクエリを使用したところ、エラー メッセージが表示されました。エラーの原因は特定できますが、どうすれば解決できますか
select min(id),customer_id,created_at from thunderbolt_orders
group by customer_id
最小 ID の customer_id と created_at が必要ですが、どうすれば達成できますか。
with cte as (
select
*, row_number() over(partition by customer_id order by id) as row_num
from Table1
)
select *
from cte
where row_num = 1
最小 ID だけが必要かどうか、または顧客ごとに最小 ID が必要かどうかに応じて、これらがソリューションになります。
最小 ID:
select top 1 id,customer_id,created_at from thunderbolt_orders order by id asc
各顧客の最小 ID:
with cte as (
select min(id) as id
from thunderbolt_orders
group by customer_id
)
select *
from cte c
inner join thunderbolt_orders t on t.id = c.id