关于英语查询 - 请求帮助

时间:2010-02-23 05:10:50

标签: sql-server-2000

我在印度塔塔研究开发和设计中心担任研究员。我正在探索可用的数据库自然语言接口。在探索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。 表的两个以上属性引用另一个表中的相同主键属性。

查询:“给我John和Rohit之间的所有交易”

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

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理解上述查询? 希望有人通过建议一些合适的解决方案来帮助我们。

1 个答案:

答案 0 :(得分:0)

我无法理解你所写的内容。如果你能提供你所写的确切查询,那将是有意义的。无论如何,尝试以下查询,它将工作。

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))