0

我在同一个数据库中有两个表图像和交互。我想确定具有 png 文件名(例如 1001_A01_1-4_5mM_3AT_Xgal_7d_W.cropped.resized.grey.png 的 image.images 是否类似于 plate_name.Interactions 看起来像 1001_A01 然后计算图像出现的次数。如果我想返回 plate_name.Interactions 的图像少于 3 张,我应该得到 3 张图像。我想使用 1 个查询来做到这一点。

到目前为止,我只是试图计算有多少次出现,但这失败了:

select plate_name.Interactions, count(*) as count from Interactions where plate_name.Interactions like image.images;

以下是有问题的表格:

mysql> desc images;
+------------+--------------+------+-----+---------+-------+
| Field      | Type         | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| image      | varchar(100) | NO   | MUL | NULL    |       |
| user_id    | varchar(50)  | YES  |     | NULL    |       |
| project_id | varchar(50)  | YES  |     | NULL    |       |
+------------+--------------+------+-----+---------+-------+

mysql> desc Interactions;
+----------------------+-------------+------+-----+---------+-------+
| Field                | Type        | Null | Key | Default | Extra |
+----------------------+-------------+------+-----+---------+-------+
| plate_name           | varchar(25) | NO   | MUL | NULL    |       |
| plate_number         | int(11)     | NO   | MUL | NULL    |       |
| bait_sequence_name   | varchar(25) | NO   |     | NULL    |       |
| bait_gene_promoter   | varchar(25) | NO   | MUL | NULL    |       |
| array_coord          | varchar(25) | NO   |     | NULL    |       |
| transcriptor_factor  | varchar(25) | NO   |     | NULL    |       |
| orf_name             | varchar(25) | NO   |     | NULL    |       |
| y_coord              | varchar(25) | NO   | MUL | NULL    |       |
| x_coord              | varchar(25) | NO   | MUL | NULL    |       |
| orig_intensity_value | varchar(25) | NO   |     | NULL    |       |
| rc_intensity_value   | varchar(25) | NO   |     | NULL    |       |
| ptp_intensity_value  | varchar(25) | NO   |     | NULL    |       |
| z_score              | varchar(25) | NO   | MUL | NULL    |       |
| z_prime              | varchar(20) | YES  |     | NULL    |       |
| call_type            | varchar(25) | NO   |     | NULL    |       |
| bleed_over           | varchar(25) | NO   | MUL | NULL    |       |
| plate_median         | int(11)     | YES  | MUL | NULL    |       |
| bait_gene            | varchar(25) | NO   |     | NULL    |       |
| bait_prey_orf        | varchar(25) | NO   |     | NULL    |       |
| human_call           | varchar(25) | NO   |     | NULL    |       |
| modified_call        | varchar(25) | NO   |     | NULL    |       |
| duplicate_call       | varchar(25) | YES  |     | NULL    |       |
| user_id              | varchar(25) | YES  | MUL | NULL    |       |
| project_id           | varchar(25) | YES  | MUL | NULL    |       |
+----------------------+-------------+------+-----+---------+-------+

为回应鲍比的回答而添加:

+----+-------------+--------------+-------+---------------+--------------+---------+---    ---+---------+-----------------------------------------------------------+
| id | select_type | table        | type  | possible_keys | key          | key_len | ref  | rows    | Extra                                                     |
+----+-------------+--------------+-------+---------------+--------------+---------+---    ---+---------+-----------------------------------------------------------+
|  1 | SIMPLE      | images       | index | NULL          | image        | 208     | NULL |   19581 | Using where; Using index; Using temporary; Using filesort |
|  1 | SIMPLE      | Interactions | range | plate_median  | plate_median | 5       |   NULL | 3714984 | Using where; Using join buffer                            |
+----+-------------+--------------+-------+---------------+--------------+---------+------+---------+-----------------------------------------------------------+
4

1 回答 1

0

我认为您以不正确的格式编写您的表名和列名.. 如果我是对的,查询应该只返回它少于 3 张图像的 plate_name,因此您可以使用 GROUP BY 和 HAVING 方法来完成。

SELECT Iteractions.plate_name, count(*) as `count`
FROM Interactions, Images
WHERE Interactions.plate_name LIKE Images.image
GROUP BY Interactions.plate_name
HAVING count(*) < 3

请尝试一下,并告诉我这是否不是您想要的.. :)

于 2013-04-09T14:51:11.090 回答