如何选择行,如果数据可能没有被排序?

huangapple go评论90阅读模式
英文:

How to select rows if data might not be ordered?

问题

如何从mod表中选择Id,即使查询中提供的数据顺序与我的SQLite数据库中的顺序不同?

mod表:

Id Secondary1 Secondary2 Secondary3 Secondary4
1 offense tenacity speed defense
2 offense speed protection potency
… … … … …

例如,如果我有次要属性为speed、tenacity、defense和offense的mod,我希望查询的输出是"1"。

我为每个部分的排列组合(speed、tenacity、defense、offense;speed、defense、tenacity、offense;等等)制作了查询,但这不是一个简洁的解决方案,似乎有些过度。

英文:

How to select Id from mod table even if data given in the query is not in the same order as the one in my SQLite database?

mod table:

Id Secondary1 Secondary2 Secondary3 Secondary4
1 offense tenacity speed defense
2 offense speed protection potency
… … … … …

For example if I have the mod with secondaries speed, tenacity, defense and offense I want the query output to be "1".

I made a query for every partial permutation (speed, tenacity, defense, offense; speed, defense, tenacity, offense; etc.) but it isn't a sexy solution and seems overkill.

答案1

得分: 1

一个简单的解决方案可以是多次使用 IN

例如:

  1. select * from t
  2. where Secondary1 in ('速度', '坚韧', '防御', '进攻')
  3. and Secondary2 in ('速度', '坚韧', '防御', '进攻')
  4. and Secondary3 in ('速度', '坚韧', '防御', '进攻')
  5. and Secondary4 in ('速度', '坚韧', '防御', '进攻')
英文:

A simple solution could be to just use IN multiple times.

For example:

  1. select * from t
  2. where Secondary1 in ('speed', 'tenacity', 'defense', 'offense')
  3. and Secondary2 in ('speed', 'tenacity', 'defense', 'offense')
  4. and Secondary3 in ('speed', 'tenacity', 'defense', 'offense')
  5. and Secondary4 in ('speed', 'tenacity', 'defense', 'offense')

huangapple
  • 本文由 发表于 2023年7月7日 04:13:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632265.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定