Basically I want to run the following query:
INSERT INTO historical_car_stats (historical_car_stats_id, year, month, make, model, region, avg_msrp, count)
SELECT
my_seq.nextval,
'2010',
'12',
'ALL',
'ALL',
region,
sum(avg_msrp * count) / sum(count),
sum(count)
FROM historical_car_stats
WHERE year = '2010'
AND month = '12'
AND make != 'ALL'
GROUP BY region;
It doesn't work because "sequence number not allowed here" SQL error. How can I write this so Oracle will let me do what I want to do?
I tested and the script run ok!
you can read this article to understand more! http://www.orafaq.com/wiki/ORA-02287
Assuming that you want to group the data before you generate the key with the sequence, it sounds like you want something like