Calculating values from one table and inserting into another table

  • Hello everyone,

    A few things first so that my wording makes sense:

    species_co refers to something like 'RM' (for red maple)

    species_ty for the above species_co would be 'HW' (for hardwood)

    So...

    I am very new to Oracle and to SQL. I have created a table called 'density' which I hope to populate with forestry species densities. I would like to populate the 'sptype' column in my 'density' table with the values from 'species_co' in the 'all_tree_2008' table. I have tried the following scripts:

    [font="Courier New"]insert into density (sptype)

    select species_co from all_tree_2008;[/font]

    I have also tried:

    [font="Courier New"]select species_co from all_tree_2008 a

    inner join density b

    on a.species_co=b.sptype

    order by b.plotnum, b.sampyear;[/font]

    I have also tried to add a column to the 'all_tree_2008' table by using

    [font="Courier New"]alter table all_tree_2008

    (

    sdensity number (4)

    );[/font]

    But I get the error: ORA-01735: invalid ALTER TABLE option

    My end goal is to calculate the proportion of SW and HW tree species by adding up the 'species_ty' and dividing it by the total to get a percentage. I would like to take this value and use it to populate the 'spdens' column in my 'density' table.

    I hope that this makes sense. Thanks in advance for any and all replies.:)

  • It seems that you are using ORACLE. If so, you had better post your questions to other column, Other Database(?), in this forum. You may get your answer more accurate and faster.

    In SQL Server, you first two scripts are correct. The last one should be something like below.

    ALTER TABLE TableA ALTER COLUMN colA INT

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply