【问题标题】:Regarding English Query - Request help关于英语查询 - 请求帮助
【发布时间】:2011-01-19 22:48:13
【问题描述】:

我在印度塔塔研究开发和设计中心担任研究员。我正在探索可用的数据库自然语言接口。在探索 MS 英语查询时,我发现某些类型的关系没有给出适当的答案。

我们的架构如下图所示:

Schema: 
Customer ( customer_id , customer_name, customer_address) 
Transaction ( transaction_id , customer_id_1, customer_id_2, amount) 

CUSTOMER 
cuctomer_id                customer_name        customer_address 
1                        John                        abc 
2                        Rohit                        pqr 
3                        Mark                        xyz 

TRANSACTION 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 
2                        1                        3                        300 
3                        2                        1                        300 

这里,customer_id_1 和 customer_id_2 引用了 Customer.customer_id。 一个表的两个以上属性指的是另一个表中的相同主键属性。

查询:“给我约翰和罗希特之间的所有交易”

我们创建的实体是客户和交易;对于给定的英文查询,在客户和交易之间建立了以下关系-

Relationship Type : Noun Verb 
Relationship: Transaction are 
Preposition Clause: between Customer(customer_id_1) 
Preposition Clause: and Customer_1(customer_id_2) 

这里我们定义了两个不同的客户角色(通过2个join path-customer_id_1和customer_id_2)

我们期望的输出是 trasaction_id 为 1 和 3 的交易,但它仅加入 customer_id_1 并给出结果为

Expected Output- 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 
3                        2                        1                        300 

Actual Output- 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 
2                        1                        3                        300 

这是因为我们在介词子句中定义的默认和和和之间的歧义..

我们也尝试过建立另一种关系

1) 
Relationship Type : Noun Verb 
Relationship: Transaction are 
Preposition Clause: by Customer(customer_id_1) 
Preposition Clause: to Customer_1(customer_id_2) 
2) 
Relationship Type : Noun Verb 
Relationship: Transaction are 
Preposition Clause: by Customer(customer_id_2) 
Preposition Clause: to Customer_1(customer_id_1) 

我们期望的输出是 trasaction_id 为 1 和 3 的交易,这里它同时加入了 customer_id_1 和 customer_id_2, 但是只使用了关系1,而不是1和2,所以输出如下

Expected Output- 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 
3                        2                        1                        300 

Actual Output- 
transaction_id        customer_id_1        customer_id_2        amount 
1                        1                        2                        200 

是否有一种变通方法来创建可以使 MSEQ 理解上述查询的关系? 希望有人通过提出一些适当的解决方案来帮助我们。

【问题讨论】:

  • Mseq 是 SQL Server 2000 和旧技术......这就是为什么没有人回答

标签: sql-server-2000


【解决方案1】:

我无法理解你写的长篇大论。如果您可以提供您编写的确切查询,那将是有意义的。无论如何,尝试以下查询,它会工作。

SELECT [Transaction_Id]
      ,[Customer_Id_1]
      ,[Customer_Id_2]
      ,[Amount]
  FROM [TEST].[dbo].[Transaction] WHERE ((Customer_Id_1 = 1 AND Customer_Id_2 = 2)OR(Customer_Id_1 = 2 AND Customer_Id_2 = 1))

【讨论】:

  • 感谢您的回复,我知道如何为给定的查询编写 SQL,我们必须使用 English Query 来执行此操作,这是 Microsoft SQL Server 2000 附带的工具,它应该将其转换为 SQL你说的,但它失败了,因此我问了这个问题..
猜你喜欢
  • 2014-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-18
  • 1970-01-01
相关资源
最近更新 更多