www.webdeveloper.com
Results 1 to 8 of 8

Thread: Counting Columns Catostrophes

  1. #1
    Join Date
    Aug 2005
    Location
    mars
    Posts
    223

    Smile Counting Columns Catostrophes

    If you saw my Simple Decimal Problem, this is the same database. I got the decimal fixed but then I tried to add a totals column.

    drop database expenses2006;
    create database expenses2006;
    use expenses2006;
    create table january (
    id int not null auto_increment,
    Date varchar(5),
    Description varchar(50),
    Office_Exp decimal(5,2),
    Dues_Public decimal(5,2),
    Business_Lunch decimal(5,2),
    Conf_Cont_ED decimal(5,2),
    Supplies_for_Prod decimal(5,2),
    Small_Equip decimal(5,2),
    Prom_Adv decimal(5,2),
    Travel decimal(5,2),
    Freight decimal(5,2),
    Photo decimal(5,2),
    Post decimal(5,2),
    total decimal(6,2),
    primary key(id)
    );

    insert into january (Date, Description) values ("0 0", "omit");
    insert into january (Description, Office_Exp, Dues_Public, Business_Lunch, Conf_Cont_ED, Supplies_for_Prod, Small_Equip, Prom_Adv, Travel, Freight, Photo, Post, total)
    values ("Totals", sum(january.Office_Exp), sum(january.Office_Exp), sum(january.Dues_Public), sum(january.Business_Lunch), sum(january.Conf_Cont_ED), sum(january.Office_Exp), sum(january.Office_Exp), sum(january.Supplies_for_Prod), sum(january.Small_Equip), sum(january.Prom_Adv), sum(january.Travel), sum(january.Freight), sum(january.Photo), sum(january.Post), sum(january.Office_Exp) + sum(january.Dues_Public) + sum(january.Business_Lunch) + sum(january.Conf_Cont_ED) + sum(january.Supplies_for_Prod) + sum(january.Small_Equip) + sum(january.Prom_Adv) + sum(january.Travel) + sum(january.Freight) + sum(january.Photo) + sum(january.Post));

    I get an error saying column count doesn't match count at row 1.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,633
    In the second insert statement, you have 13 columns in the columns list but 16 items in the values list.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2005
    Location
    mars
    Posts
    223
    Oh! Duhh! How could I not see that. Thanks. The world needs more people like you.

  4. #4
    Join Date
    Aug 2005
    Location
    mars
    Posts
    223
    Now I get a invalid use of group error.

  5. #5
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    1,138
    Could you post your code as it is now?

  6. #6
    Join Date
    Aug 2005
    Location
    mars
    Posts
    223
    Sorry,

    Code:
    drop database expenses2006;
    create database expenses2006;
    use expenses2006;
    create table january (
    id int not null auto_increment,
    Date varchar(5),
    Description varchar(50),
    Office_Exp decimal(5,2),
    Dues_Public decimal(5,2),
    Business_Lunch decimal(5,2),
    Conf_Cont_ED decimal(5,2),
    Supplies_for_Prod decimal(5,2),
    Small_Equip decimal(5,2),
    Prom_Adv decimal(5,2),
    Travel decimal(5,2),
    Freight decimal(5,2),
    Photo decimal(5,2),
    Post decimal(5,2),
    total decimal(6,2),
    primary key(id)
    );
    
    insert into january (Date, Description) values ("0 0", "omit");
    insert into january (Description, Office_Exp, Dues_Public, Business_Lunch, Conf_Cont_ED, Supplies_for_Prod, Small_Equip, Prom_Adv, Travel, Freight, Photo, Post, total)
    values ("Totals", sum(january.Office_Exp), sum(january.Dues_Public), sum(january.Business_Lunch), sum(january.Conf_Cont_ED), sum(january.Supplies_for_Prod), sum(january.Small_Equip), sum(january.Prom_Adv), sum(january.Travel), sum(january.Freight), sum(january.Photo), sum(january.Post), sum(january.Office_Exp) + sum(january.Dues_Public) + sum(january.Business_Lunch) + sum(january.Conf_Cont_ED) + sum(january.Supplies_for_Prod) + sum(january.Small_Equip) + sum(january.Prom_Adv) + sum(january.Travel) + sum(january.Freight) + sum(january.Photo) + sum(january.Post));

  7. #7
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    1,138
    In looking at your query, I can see that you are trying to insert data into the Description twice. Is this meant to be? Also, what is the exact error you are getting?

  8. #8
    Join Date
    Aug 2005
    Location
    mars
    Posts
    223
    - That's the error.
    - You mean with the inserting the omit? Yes, that was just a test.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles