gpt4 book ai didi

mysql - 比较 select 语句的输出

转载 作者:行者123 更新时间:2023-11-29 02:17:57 24 4
gpt4 key购买 nike

我的表 1

    |  Participantsid   |   Validfrom         |    Validto          | 
| 2,4,1 | 2016-02-21 10:22:00 | 2016-02-21 12:22:00 |
| 2,4,1 | 2016-03-04 10:00:00 | 2016-03-04 10:25:00 |
| 2,3,4,1 | 2016-02-19 10:43:00 | 2016-02-19 11:08:00 |
| 2,3,4,1 | 2016-02-22 11:32:00 | 2016-02-22 11:57:00 |
| 4,6,5 | 2016-02-20 17:00:00 | 2016-02-20 18:00:00 |
| 1,2,5 | 2016-02-22 18:00:00 | 2016-02-22 19:00:00 |
| 2,3,6,1 | 2016-03-23 10:00:00 | 2016-03-23 11:00:00 |
| 1,2,3,5 | 2016-02-20 12:00:00 | 2016-02-20 14:00:00 |
| 2,6 | 2016-02-20 12:00:00 | 2016-02-20 13:00:00 |

另一个表2

+--------------+------------+
| EmployeeName | EmployeeID |
+--------------+------------+
| Mathews | 1 |
| Gerald | 2 |
| Bravo | 3 |
| Smith | 4 |
| George | 5 |
| Bailey | 6 |
| Stephen | 9 |
| Balu c | 10 |

我有一些 inputid's=1,5,6。现在我必须将此输入 ID 与来自 table1 的 Participantsid 比较给定的有效日期和有效日期,如果匹配,我需要获取与该 ID 对应的名称。

Emaple:- inputid's=1,2,3 for from- 2016-02-22 18:00:00, to-2016-02-22 19:00:00它应该给我 o/p =mathews,gerald

我目前正在编写两个 select 语句并使用一个 for 循环,它给出了结果但它是错误的

我正在尝试在单个查询中执行此操作,但无法接近我所需的输出。请帮忙

最佳答案

使用 group_concatfind_in_setsub-query 可以达到预期的结果。

SQLFiddle: http://sqlfiddle.com/#!9/ce893/1

select group_concat(EmployeeName) as `o/p`
from Table2
where FIND_IN_SET(EmployeeID,
(select Participantsid from Table1
where Validfrom = '2016-02-22 18:00:00' and Validto = '2016-02-22 19:00:00'));

关于mysql - 比较 select 语句的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36492259/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com