【问题标题】:Error Code: 1054. Unknown column 's.Product_id' in 'on clause'Error Code: 1054. Unknown column 's.Product_id' in 'on clause'错误代码:1054。“on 子句”中的未知列“s.Product_id”错误代码:1054。“on 子句”中的未知列“s.Product_id”
【发布时间】:2017-08-04 01:09:46
【问题描述】:

我在 MySQL 中有错误:Error Code: 1054. Unknown column 's.Product_id' in 'on clause'

它出现在:

SELECT c.customer_ID, p.Product_id, p.Product_price, s.Items_quantity, (p.Product_price * s.Items_quantity) AS total FROM Products p LEFT JOIN Shopping_list s ON p.Product_id = s.Product_id LEFT JOIN Customer_sign_in c ON c.customer_ID = s.customer_ID LIMIT 0, 50000

有人知道为什么会这样吗?

【问题讨论】:

    标签: mysql mysql-error-1054


    【解决方案1】:

    你应该使用左连接

    select c.customer_ID, p.Product_id, p.Product_price, s.Items_quantity,
        (p.Product_price * s.Items_quantity) as total from Products p LEFT JOIN Shopping_list s ON p.Product_id = s.Product_id LEFT JOIN Customer_sign_in c ON c.customer_ID = s.customer_ID;
    

    【讨论】:

    • 现在等待它向我显示另一个错误:错误代码:1054。“on 子句”中的未知列“s.Product_id”
    • 是的,但是当我在我的 mysql 中更改它时,它向我显示了这个错误......我不知道为什么。
    【解决方案2】:

    你确定你有表Shopping_list 和一个名为Product_id 的列吗?

    如果没有,请创建列并重试。

    【讨论】:

    • 是的,我有两张桌子。
    【解决方案3】:
    drop database if exists shopmeout;
    create database shopmeout;
    use shopmeout;
    drop table if exists Customer_sign_in;
    
    CREATE TABLE Customer_sign_in (
        customer_ID INT (50) not null,
        Name_customer varchar(255) not null,
        Credit_card BIGINT(100) not null,
        Password_cust TEXT(150) not null,
        Email_cust TEXT(50) not null,
        primary key (customer_ID)
    );
    insert into Customer_sign_in values( 19867889, 'Stefan Darescu', 9018783269173917, 'personalcomputer84', 'stefandarescu@gmail.com');
    insert into Customer_sign_in values( 11958178, 'Mogens Hemming', 5090180120973782,'masadebiliard4', 'mogenshemming@yahoo.com');
    insert into Customer_sign_in values( 52562523, 'Viggo Kristian', 9015908218093698,'asawece', 'viggokristian@gmail.com');
    insert into Customer_sign_in values( 42515323, 'Asbjørn Hjalmar', 0198490128761903,'esrjgads', 'asbjornhjalmar@hotmail.com');
    insert into Customer_sign_in values( 69723642, 'Rasmus Bjarne', 9180583647839793,'Sgsyhdfs', 'rasmusbjarne@outlook.com');
    
    CREATE TABLE Products (
        Product_id INT(150) not null,
        Product_name VARCHAR(100) not null,
        Product_price DECIMAL(6,2) not null,
        Deduction_price INT(50) not null,
        Deadline DATE not null,
        PRIMARY KEY (Product_id)
    );
    insert into Products values( 509687, 'Plain Flower', 59.46, 10, '2013-05-30');
    insert into Products values( 485901, 'Cow Milk', 17.85, 12, '2013-04-18');
    insert into Products values( 908571, 'Kærgården', 131.75, 8, '2013-04-07');
    insert into Products values( 432612, 'Chicken Eggs', 27.57, 9, '2013-03-31');
    insert into Products values( 853235, 'Pepsi Cherry', 25.11, 12, '2013-03-25');
    insert into Products values( 357342, 'Spaghetti', 10.8, 5, '2013-03-20');
    insert into Products values( 123563, 'Spaghetti sos', 22.4, 10, '2013-03-17');
    
    delimiter //
    CREATE TRIGGER first_trigger BEFORE UPDATE ON Products
    FOR EACH ROW
    BEGIN
     IF NEW.Product_price < 20 THEN
     SET NEW.Product_price = 15;
     ELSEIF NEW.Product_price > 140 THEN
     SET NEW.Product_price = 80;
     END IF;
    END;//
    delimiter ;
    UPDATE Products set Product_price = 25 where Product_id = 509687;
    UPDATE Products set Product_price = 22 where Product_id = 908571;
    
    CREATE TABLE Recipes (
        Recipes_id INT (10) not null,
        Recipe_name CHAR (150) not null,
        Recipe_descrip TEXT(255) not null,
        primary key (Recipes_id)
    );
    insert into Recipes values( 513678, 'Pancakes', 'Crack the eggs into a blender, add the flour, milk and a pinch of sea salt, and blitz until smooth.');
    insert into Recipes values( 867523, 'Spaghetti Bolognese', 'Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat.');
    
    CREATE TABLE Shopping_list (
        Shopping_list_id INT (50) not null,
        customer_ID INT (50) not null,
        Items_quantity INT (50) not null,
        primary key (Shopping_list_id),
        foreign key (customer_ID)
            REFERENCES
        Customer_sign_in (customer_ID)
    );
    insert into Shopping_list values( 14081869, 19867889, 15);
    insert into Shopping_list values( 15163266, 11958178, 30);
    insert into Shopping_list values( 34232325, 52562523, 3);
    insert into Shopping_list values( 82412845, 42515323, 7);
    insert into Shopping_list values( 36272236, 69723642, 5);
    
    CREATE TABLE Payment (
        Payment_id INT(150) NOT NULL,
        customer_ID INT(150) NOT NULL,
        Date_pay DATETIME NOT NULL,
        Shopping_list_id INT(50) NOT NULL,
        PRIMARY KEY (Payment_id),
        FOREIGN KEY (customer_ID)
            REFERENCES Customer_sign_in (customer_ID),
        FOREIGN KEY (Shopping_list_id)
            REFERENCES Shopping_list (Shopping_list_id)
    );
    insert into Payment values( 84163801, 19867889, '2013-05-25 07:12:00', 14081869);
    insert into Payment values( 89171750, 11958178, '2013-04-08 21:43:12', 15163266);
    insert into Payment values( 19829247, 52562523, '2013-04-02 16:41:09', 34232325);
    insert into Payment values( 35819204, 42515323, '2013-03-25 23:54:32', 82412845);
    insert into Payment values( 25085739, 69723642, '2013-03-20 12:38:56', 36272236);
    
    CREATE TABLE Has (
        Product_id INT(150) NOT NULL,
        Recipes_id INT(150) NOT NULL,
        FOREIGN KEY (Product_id)
            REFERENCES Products (Product_id),
        FOREIGN KEY (Recipes_id)
            REFERENCES Recipes (Recipes_id)
    );
    insert into Has values( 509687, 513678);
    insert into Has values( 485901, 513678);
    insert into Has values( 908571, 513678);
    insert into Has values( 357342, 867523);
    insert into Has values( 123563, 867523);
    
    CREATE TABLE Goes (
        Product_id INT(150) NOT NULL,
        Shopping_list_id INT(150) NOT NULL,
        FOREIGN KEY (Product_id)
            REFERENCES Products (Product_id),
        FOREIGN KEY (Shopping_list_id)
            REFERENCES Shopping_list (Shopping_list_id)
    );
    insert into Goes values( 485901, 14081869);
    insert into Goes values( 123563, 14081869);
    insert into Goes values( 908571, 14081869);
    insert into Goes values( 485901, 82412845);
    insert into Goes values( 123563, 34232325);
    insert into Goes values( 357342, 34232325);
    
    select * from Shopping_list;
    select * from Payment;
    select * from Customer_sign_in;
    select * from Recipes;
    select * from Products;
    select * from Has;
    select * from Goes;
    
    SELECT c.customer_ID, p.Product_id, p.Product_price, s.Items_quantity,
    (p.Product_price * s.Items_quantity) AS total FROM Products p LEFT JOIN Shopping_list s ON p.Product_id = s.Product_id LEFT JOIN Customer_sign_in c ON c.customer_ID = s.customer_ID;
    

    【讨论】:

      猜你喜欢
      • 2021-02-18
      • 1970-01-01
      • 2016-03-19
      • 1970-01-01
      • 2020-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多