gpt4 book ai didi

sql - 来自 delphi 的 Access db 中的多个 INNER JOINS

转载 作者:行者123 更新时间:2023-12-03 04:18:47 25 4
gpt4 key购买 nike

我编写了连接到 acceessdb 的最简单程序,并且可以从 Memo 列执行 SQL 查询。

示例查询:

SELECT 
company_name, date_of_order_start, date_of_order_finish
FROM
customers
INNER JOIN
orders ON customers.id_customer = orders.id_customer
WHERE
company_name='Ампер';

它工作正常,但是这个查询

SELECT 
company_name, date_of_order_start, date_of_order_finish, amount
FROM
customers
INNER JOIN
orders ON customers.id_customer = orders.id_customer
INNER JOIN
invoice ON invoice.id_order = orders.id_order
WHERE
company_name='Ампер';

返回语法错误

missing operator in expression 'customers.id_customer=orders.id_customer INNER JOIN invoice ON invoice.id_order=orders.id_orde' .

是的,.id_order 中的最后一个 r 未显示。

请帮忙,我哪里出错了。

程序代码如下

    unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Vcl.StdCtrls, Vcl.DBCtrls,
Vcl.Grids, Vcl.DBGrids, Vcl.ExtCtrls, Data.Win.ADODB;

type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
Panel1: TPanel;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Label1: TLabel;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Memo1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
//проверим - есть ли текст в Memo. Если нет, выходим:
if Memo1.Text = '' then begin
ShowMessage('Вначале введите запрос!');
Memo1.SetFocus;
Exit;
end;
//текст есть. Очистим предыдущий запрос в наборе данных:
ADOQuery1.SQL.Clear;
//добавим новый запрос из Memo:
ADOQuery1.SQL.Add(Memo1.Text);
//открываем набор данных, т.е. выполняем запрос:
ADOQuery1.Open;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.Clear;
end;

procedure TForm1.Memo1Change(Sender: TObject);
begin
ADOQuery1.SQL.Add(Memo1.Text);
ADOQuery1.SQL := Memo1.Lines;
end;


end.

最佳答案

非常感谢所有尝试帮助我的人!

在access db中JOIN必须在()中,所以这个查询工作正常:

 SELECT 
company_name, date_of_order_start, date_of_order_finish, amount
FROM
(customers
INNER JOIN orders ON customers.id_customer=orders.id_customer)
INNER JOIN invoice ON invoice.id_order=orders.id_order
WHERE company_name='Ампер';

关于sql - 来自 delphi 的 Access db 中的多个 INNER JOINS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37590976/

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