mysql - 在扑克牌中找到四张相同的牌

标签 mysql

这是我的表格

pokerHands
+----------+--------+----+-----+----+----+----+
| playerId | gameId | R1 | R2  | R3 | R4 | R5 |
+----------+--------+----+-----+----+----+----+
|    12789 | 17MET  | QH | QS  | 3D | 3C | 3H |
|    12789 | 82SAT  | 7C | 4S  | 4D | 4C | 3H |
|    56347 | 03DEC  | 3S | 6S  | 3H | 3C | 3D |
|    56347 | 23WSA  | KH | 10H | 7H | 3H | AH |
|    84643 | 78GUV  | 9H | 7C  | 5H | 5C | 2S |
|    90734 | 65YOB  | QH | JH  | 8C | 8S | 8D |
+----------+--------+----+-----+----+----+----+

select * from pokerCards limit 5;
+----------+------+------+------+-----------+-----------+
| cardName | face | type | suit | faceValue | gameValue |
+----------+------+------+------+-----------+-----------+
| 10C      | no   | 10   | C    |        10 |        10 |
| 10D      | no   | 10   | D    |        10 |        10 |
| 10H      | no   | 10   | H    |        10 |        10 |
| 10S      | no   | 10   | S    |        10 |        10 |
| 2C       | no   | 2    | C    |         2 |         2 |
+----------+------+------+------+-----------+-----------+

playerId和gameId是第一个表pokerHands中的复合主键,而cardName是第二个表中的主键。

我正在尝试找出如何从第一个表中选择一个四,这将从当前的 pokerHands 表中返回它

+----------+--------+----+-----+----+----+----+
| playerId | gameId | R1 | R2  | R3 | R4 | R5 |
+----------+--------+----+-----+----+----+----+
|    56347 | 03DEC  | 3S | 6S  | 3H | 3C | 3D |
+----------+--------+----+-----+----+----+----+

非常感谢任何帮助。

最佳答案

试试这个:

select playerId, gameId, R1, R2, R3, R4, R5 from pokerHands as ph
join pokerCards as pc1 on pc1.cardName=ph.R1
join pokerCards as pc2 on pc2.cardName=ph.R2
join pokerCards as pc3 on pc3.cardName=ph.R3
join pokerCards as pc4 on pc4.cardName=ph.R4
join pokerCards as pc5 on pc5.cardName=ph.R5
where ( (pc1.type=pc2.type) and (pc1.type=pc3.type) and (pc1.type=pc4.type) )
or ( (pc1.type=pc2.type) and (pc1.type=pc3.type) and (pc1.type=pc5.type) )
or ( (pc1.type=pc2.type) and (pc1.type=pc4.type) and (pc1.type=pc5.type) )
or ( (pc1.type=pc3.type) and (pc1.type=pc4.type) and (pc1.type=pc5.type) )
or ( (pc2.type=pc3.type) and (pc2.type=pc4.type) and (pc2.type=pc5.type) )

关于mysql - 在扑克牌中找到四张相同的牌,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42260710/

相关文章:

mysql - 在单个查询中查找各种表中的总记录

php - 超过 64kb 的内容未显示在 WordPress 中

php - IE 查询参数中的 UTF-8 编码问题

Python MySQL 长查询插入或更新

fetch_array 中的 PHP MySQL 数组

mysql 同一表记录中的2行比较

mysql - "Categorize"或 "Mark"选择查询

mysql - 即使所有内容都应该匹配,SQL Like 或 REGEXP 也会过滤结果

mysql - 可以配置 Sphinx ---> 以获得与 MySQL 全文搜索相同的结果

MYSQL错误:com. mysql.jdbc.NotUpdatable