简体   繁体   English

sql查询以查找匹配属性

[英]sql queries to find the match attributes

i am currently doing a system like bartering system. 我目前正在做一个像易货系统这样的系统。 the situation like this . 像这样的情况。 A customer (Jasmine) require to input the 'NAME' attribute (what she have to seek) and input the'SEEK' attribute (what she need to seek). 客户(Jasmine)需要输入'NAME'属性(她必须要搜索的内容)并输入'''''属性(她需要搜索的内容)。 In order to get the result, the 'SEEK' attribute must match with 'Name' attribute from other customer and the 'SEEK' attribute from other customer must match with 'HAVE' attribute from Jasmine. 为了获得结果,“SEEK”属性必须与来自其他客户的“Name”属性匹配,而来自其他客户的“SEEK”属性必须与Jasmine的“HAVE”属性匹配。

for example i have table items (already in database) 例如我有表项(已在数据库中)

|ITEMSID|NAME   |SEEK     |USERID|
|A01    |printer|laptop   |A1    |
|A45    |laptop |headphone|A2    |
|AY3    |laptop |headphone|A3    |

For example Jasmine has 'Name' attribute headphone and 'Seek' attribute laptop and the result should like this. 例如,Jasmine有'Name'属性耳机和'Seek'属性笔记本电脑,结果应该是这样的。 The result should list out all possibility (it may consists more than one row depends, and it may get zero result if the are no match betwen 'NAME' AND 'SEEK' attribute 结果应列出所有可能性(它可能包含多个行,如果“NAME”和“SEEK”属性之间不匹配,则结果可能为零

|ITEMSID|NAME   |SEEK     |USERID|
|AY3    |laptop |headphone|A3    |
|A45    |laptop |headphone|A2    |

Thank you for helping me. 感谢你们对我的帮助。 The system that i'm being develop using jsp p/s: i'm a new user in stackoverflow. 我正在使用jsp p / s开发的系统:我是stackoverflow中的新用户。

EDIT based on comments: 根据评论编辑:

I already tried using an inner join but the query result is not specific on one transaction (mean the result match between 'Have' and 'Seek' attribute, but has all the matching rows and not the choose the 'Have' attribute that being input): 我已经尝试过使用inner join但查询结果并不是特定于一个事务(意味着'Have'和'Seek'属性之间的结果匹配,但是具有所有匹配的行而不是选择输入的'Have'属性):

SELECT a.NAME, a.seek,a.ITEMSID 
FROM items a 
JOIN items b ON a.NAME = b.seek AND b.NAME = a.seek

Based on the query you have tried, if I understand your request correctly (not sure I do), all you are missing is the WHERE clause for the input. 基于您尝试过的查询,如果我正确理解您的请求(我不确定),您所缺少的只是输入的WHERE子句。

SELECT a.name, a.seek, a.ITEMSID 
FROM items a 
JOIN items b 
  ON a.name = b.seek 
  AND b.name = a.seek
WHERE a.name = 'input here'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM