gpt4 book ai didi

mysql - 如何连接两个表并在第三个表中显示结果

转载 作者:行者123 更新时间:2023-11-29 18:25:54 25 4
gpt4 key购买 nike

我制作了两个(Quotation1Quotation2),它具有以下,例如:

CREATE TABLE Quotation1 (
Q_No INTEGER (10),
Date DATE,
C_Code VARCHAR (45),
C_Name VARCHAR (45),
C_Contact VARCHAR (45),
G_Tot VARCHAR (45),
Remarks VARCHAR (250)
);

CREATE TABLE Quotation2 (
Q_No VARCHAR (45),
P_Code VARCHAR (45),
P_Name VARCHAR (45),
Price VARCHAR (45),
Qnty INTEGER (10),
Amt VARCHAR (45),
Discount_Per INTEGER (10),
Discount INTEGER (10),
VAT_Per INTEGER (10),
VAT INTEGER (10),
Tot_Amt VARCHAR (45)
);

我必须连接这两个并在第三个表中显示其结果引用 其中有以下,例如:

CREATE TABLE Quotation (
Q_No INT (10) PRIMARY KEY
NOT NULL,
Date DATE,
C_Code VARCHAR (45) REFERENCES CustomerInfo (C_Code) ON DELETE NO ACTION
ON UPDATE NO ACTION
MATCH SIMPLE NOT DEFERRABLE INITIALLY DEFERRED,
C_Name VARCHAR (45),
C_Contact VARCHAR (45),
Remarks VARCHAR (45),
P_Code VARCHAR (45) REFERENCES ProductInfo (P_Code) ON DELETE NO ACTION
ON UPDATE NO ACTION
MATCH SIMPLE NOT DEFERRABLE INITIALLY DEFERRED,
P_Name VARCHAR (45),
Price VARCHAR (45),
Qnty INTEGER (10),
Amount VARCHAR (45),
Discount_Per INTEGER (10),
Discount INTEGER (10),
VAT_Per INTEGER (10),
VAT INTEGER (10),
Tot_Amt VARCHAR (45),
G_Tot VARCHAR (45)
)
WITHOUT ROWID;

我已经应用了以下查询,例如:

INSERT INTO Quotation (Q_No,Date,C_Code,C_Name,C_Contact,Remarks,P_Code,P_Name,Price,Qnty,Amount,Discount_Per,Discount,VAT_Per,VAT,Tot_Amt,G_Tot)
SELECT Quotation2.Q_No,
Quotation1.Date,
Quotation1.C_Code,
Quotation1.C_Name,
Quotation1.C_Contact,
Quotation1.Remarks,
Quotation2.P_Code,
Quotation2.P_Name,
Quotation2.Price,
Quotation2.Qnty,
Quotation2.Amt,
Quotation2.Discount_Per,
Quotation2.Discount,
Quotation2.VAT_Per,
Quotation2.VAT,
Quotation2.Tot_Amt,
Quotation1.G_Tot
FROM Quotation1,
Quotation2
INNER JOIN Quotation ON Quotation1.Q_No=Quotation2.Q_No;

它给出以下结果,例如:[02:16:23]查询在0.010秒内完成。

但不显示任何数据甚至列名称请帮忙。

最佳答案

插入时为什么要加入目标表?

-- Insert
INSERT INTO Quotation (Q_No,Date,C_Code,C_Name,C_Contact,Remarks,P_Code,P_Name,Price,Qnty,Amount,Discount_Per,Discount,VAT_Per,VAT,Tot_Amt,G_Tot)
SELECT Quotation2.Q_No,
Quotation1.Date,
Quotation1.C_Code,
Quotation1.C_Name,
Quotation1.C_Contact,
Quotation1.Remarks,
Quotation2.P_Code,
Quotation2.P_Name,
Quotation2.Price,
Quotation2.Qnty,
Quotation2.Amt,
Quotation2.Discount_Per,
Quotation2.Discount,
Quotation2.VAT_Per,
Quotation2.VAT,
Quotation2.Tot_Amt,
Quotation1.G_Tot
FROM Quotation1
JOIN Quotation2 ON Quotation1.Q_No = Quotation2.Q_No;

-- Show results:
SELECT * FROM Quotation;

应该完成这项工作。

关于mysql - 如何连接两个表并在第三个表中显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46200442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com