I have a query below:
SELECT count(*) AS my_table_count
,my_table_date_value
FROM my_table
WHERE my_table_value = 500
GROUP BY my_table_date_value
This returns an array/two column table of the count and the date where the value is 500. Which is what I want.
However, i created a table like this for the results of the above query:
CREATE TABLE my_new_table (
my_table_count NUMBER(10)
,my_table_date_value DATE
,my_table_value NUMBER(38)
)
What I want to do is fill the new table with all of the data from the first query, where my_table_value > 0
I tried using insert into (select...), but I'm not sure how to populate the my_table_value that way. I'm thinking iterating from 1 to the max(my_table_value) would do it but i'm not sure how to write this in Oracle SQL.
The result I want is where I can query my_new_table instead of using the first query as following:
SELECT my_table_count
,my_table_date_value
FROM my_new_table
WHERE my_table_value = 500;
EDIT
Here's what I do now for one value (say 500). All I want to do is go back and get the values 0-499 in the table.
SET my_value = 500;
SET sqlString = 'select COUNT(*) AS MY_COUNT,MY_DATE from MY_TABLE where MY_VALUE=? group by MY_DATE';
SET rows[] = <query result, with my_value = 500>
DECLARE index INTEGER 1;
FOR result as r.rows[] DO
SET count = result.MY_COUNT;
SET my_date = result.MY_DATE;
insert into MY_NEW_TABLE(MY_COUNT,MY_DATE,MY_VALUE)
VALUES(count,my_date,my_value);
SET index = index + 1;
END FOR;
All I want to do is modify this, so it inserts everything from 1 to max(my_value)