Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2009
    Location
    Bucharest
    Posts
    6

    Red face Unanswered: help - issues creating table ( beginner )

    I have this code:
    create table tcor(mf float(10), ls float(10));

    insert into tcor(mf) select vanzaria.cant from vanzaria where vanzaria.codb='mf';
    insert into tcor(ls) select vanzaria.cant from vanzaria where vanzaria.codb='ls';
    when i query for "select * from tcor", it gives me the result like this:

    indx___mf____ls
    1_____10
    2_____20
    3_____30
    4 __________35
    5 __________45
    6 __________55


    It seems like it writes the second column at the end of the first column, but i want the values of ls to be on the lines 1, 2, 3 also.
    Could somebody help me figure out what I should do?
    Thank you very much !!!

    Songe Patricia
    Last edited by songe; 06-30-09 at 11:56.

  2. #2
    Join Date
    Jun 2004
    Posts
    796
    Provided Answers: 1
    If I understand you, you need to read about CREATE and UPDATE.
    90% of users' problems can be resolved by punching them - the other 10% by switching off their PCs.

  3. #3
    Join Date
    Dec 2003
    Posts
    1,074
    You don't have a value upon which to combine rows (ie a Foreign Key). Or do you just want the data to "appear" as if it's all from the same row?

    Code:
    select nvl(mf, ls) as field1
    from tcor
    --=cf

  4. #4
    Join Date
    Jun 2009
    Location
    Bucharest
    Posts
    6
    Thank you very much for reading my post, whatever the result will be.

    I wanted to create a table with 2 columns, with data from a tablem let's say originalTable.
    One column with the values of cant for mf, one with the values of cant for ls.
    (in the original table there is the same number of rows for each product;
    it also contains more products, but i am interested only in these 2
    I need them also in the same order as in the original table-for each month)

    But maybe it is a bad idea.

    What I actually have to do is smth like :
    sum((originalTable.cant of mf) *(originalTable.cant of ls)) group by month. (actualy it's not month in my table , it's an index , but it is a symbol for time)

    I don't think that i can simply use "where" to solve this in a way. but how to solve this?

    Now I'm thinking I should put all these values in 2 arrays, if there is a way to do so. I'll have a search on the internet about this.

    thanks,
    Songe Patricia





    Quote Originally Posted by chuck_forbes
    You don't have a value upon which to combine rows (ie a Foreign Key). Or do you just want the data to "appear" as if it's all from the same row?

    Code:
    select nvl(mf, ls) as field1
    from tcor
    --=cf
    Last edited by songe; 06-30-09 at 12:56.

  5. #5
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool Group by key

    Patricia,

    if indx (or month or ...) is the key, try something like this:
    Code:
    INSERT INTO tcor
                (indx, mf, ls)
       SELECT   indx
              , SUM (DECODE (vanzaria.codb, 'mf', vanzaria.cant, 0))
              , SUM (DECODE (vanzaria.codb, 'ls', vanzaria.cant, 0))
           FROM vanzaria
       GROUP BY indx;
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  6. #6
    Join Date
    Jun 2009
    Location
    Bucharest
    Posts
    6
    Thank u LKBrwn_DBA!
    Very nice idea to use the decode function
    I'm not used to play with all the sql stuff, but I like (in a kind of masochistic way )) )the way it force you to improve, compared to other languages-that are more flexible (I'm new to sql).

    Have a brilliant day !


    Quote Originally Posted by LKBrwn_DBA
    Patricia,

    if indx (or month or ...) is the key, try something like this:
    Code:
    INSERT INTO tcor
                (indx, mf, ls)
       SELECT   indx
              , SUM (DECODE (vanzaria.codb, 'mf', vanzaria.cant, 0))
              , SUM (DECODE (vanzaria.codb, 'ls', vanzaria.cant, 0))
           FROM vanzaria
       GROUP BY indx;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •