I have a table:
create table practice_table
(
traffic_date datetime ,
door_one integer ,
door_two integer
)
With some sample data:
insert into practice_table(traffic_date, door_one, door_two) values ('12-Oct-2006' ,14500 ,11141)
insert into practice_table(traffic_date, door_one, door_two) values ('13-Oct-2006' ,6804 ,5263)
insert into practice_table(traffic_date, door_one, door_two) values ('14-Oct-2006' ,7550 ,6773)
insert into practice_table(traffic_date, door_one, door_two) values ('15-Oct-2006' ,6144 ,5211)
insert into practice_table(traffic_date, door_one, door_two) values ('16-Oct-2006' ,5680 ,3977)
insert into practice_table(traffic_date, door_one, door_two) values ('17-Oct-2006' ,5199 ,3918)
insert into practice_table(traffic_date, door_one, door_two) values ('18-Oct-2006' ,5298 ,3631)
I’m trying to move this into another table (called destination_table) that has the columns:
month (datetime)
traffic_count (integer)
How do I create a loop in SQL to create one row for October in the new table with the total of door_one and door_two without explicitly typing any data in (such as the month)?
You could use a cursor, but if I understand what your trying to do, then it’s not necessary.