sql查询以找到匹配属性 [英] sql queries to find the match attributes

查看:79
本文介绍了sql查询以找到匹配属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在做类似物物交换的系统.这样的情况.客户(茉莉花)需要输入"NAME"属性(她必须寻找的内容)并输入"SEEK"属性(她需要寻找的内容).为了获得结果,"SEEK"属性必须与其他客户的名称"属性匹配,而其他客户的"SEEK"属性必须与Jasmine的"HAVE"属性匹配.

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

例如,我有表项(已经在数据库中)

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    |

例如,茉莉花具有名称"属性的耳机和搜索"属性的笔记本电脑,其结果应如下所示.结果应该列出所有可能性(它可能包含多个行依赖项,如果'NAME'和'SEEK'属性之间不匹配,则结果可能为零

For example Jasmine has 'Name' attribute headphone and 'Seek' attribute laptop and the result should like this. 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

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

感谢您对我的帮助.我正在使用jsp开发的系统 p/s:我是stackoverflow中的新用户.

Thank you for helping me. The system that i'm being develop using jsp p/s: i'm a new user in stackoverflow.

根据评论进行

我已经尝试过使用inner join,但是查询结果不是特定于一个事务的(意思是'Have'和'Seek'属性之间的结果匹配,但是具有所有匹配的行,而不是选择'Have'输入的属性):

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

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

推荐答案

根据您尝试过的查询,如果我正确理解了您的请求(不确定我是否知道),则您所缺少的只是WHERE子句输入.

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.

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'

这篇关于sql查询以找到匹配属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆