commonprofit という名前のテーブルがあり、次の 3 つのフィールドがあります:名前、日付、利益。
select name,max(date) from commonprofit group by name
コマンドは、グループごとに日付が最大の多くのレコードを取得できます。name
コマンドで選択されたすべてのレコードを削除したいのですが、次のようにできないのはなぜですか:
drop from commonprofit where date in (select name,max(date) from commonprofit group by name);
delete from commonprofit where date=max(date) group by name;
delete from commonprofit where date in (select name,max(date) from commonprofit group by name);
どちらもできません。
プリミティブ データは次のとおりです。
name date profit
1 2011/12 42359
1 2010/12 32863
1 2009/12 24293
1 2008/12 16436
1 2007/12 15442
2 2011/12 91634
2 2010/12 58410
2 2009/12 50668
2 2008/12 54297
3 2009/12 12352
3 2008/12 12352
3 2007/12 14226
私が削除したいのは:
name date profit
1 2011/12 42359
2 2011/12 91634
3 2009/12 12352
私が取得したいのは:
name date profit
1 2010/12 32863
1 2009/12 24293
1 2008/12 16436
1 2007/12 15442
2 2010/12 58410
2 2009/12 50668
2 2008/12 54297
3 2008/12 12352
3 2007/12 14226
どのようにできるのか?