[英]how to select record from table where record have the most similar attribute from another table
TABLE A 表A
result select 结果选择
A a a
B a a
B b b
C a a
C b 碳
C c 碳
TABLE B 表B
user select 用户选择
1 a 1个
1 b 1例
2 b 2例
2 c 2点
TABLE C 表C
user result 用户结果
1 B 1个
2 C 2℃
what mysql query should i have to use, if i want to do like this: 如果我想这样做,我应该使用什么mysql查询:
if user select a the result is ABC (because ABC have 'a' in column 'select') if user select ab the result is BC (because A doesn't have 'b' in column 'select') if user select abc the result is C (because C have 'abc' in column 'select') if user select bc the result is C (because AB doesn't have 'c' in column 'select') if user select c the result is C (because AB doesn't have 'c' in column 'select') 如果用户选择一个结果,则结果为ABC(因为ABC在“选择”列中有“ a”);如果用户选择a,则结果是BC(因为A在“选择”列中没有“ b”);如果用户选择了abc,则如果用户选择bc,则结果为C(因为C在“选择”列中具有“ abc”),如果用户选择b,则结果为C(因为AB在“选择”列中不具有“ c”),如果用户选择c,则结果为C(因为AB在“选择”列中没有“ c”)
so it will select the record that have the most similar from what user selected and ignore the other record that doesn't match.. sorry for my english, i'm speak bahasa... 因此它将从用户选择的内容中选择最相似的记录,而忽略其他不匹配的记录..对不起我的英语,我说巴哈萨语...
SELECT `result`
FROM tableA
WHERE `select` IN ('a','b','c')
GROUP BY result
HAVING COUNT(*) = 3
if a unique constraint was not enforce on select
for every result
, a DISTINCT
is required. 如果没有对每个result
select
施加唯一约束,则需要DISTINCT
。
SELECT `result`
FROM tableA
WHERE `select` IN ('a','b','c')
GROUP BY result
HAVING COUNT(DISTINCT `select`) = 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.