gpt4 book ai didi

mysql - 从表中获取符合条件的多条记录

转载 作者:行者123 更新时间:2023-11-30 01:25:14 24 4
gpt4 key购买 nike

我有两个名为 OFFICE_GROUP 和 OFFICE_IPS 的表,

OFFICE_GROUP

OFFICEIPS

我想得到像得到 4 行这样的结果: RESULT

使用的查询是这样的:

SELECT (SELECT oip.IP as IP FROM OFFICE_IPS oip, OFFICE_GROUP og WHERE og.OFFICE_GROUP_ID = oip.OFFICE_GROUP_ID
AND og.MODULES like '%1%' lIMIT 1) AS SEMINAR,
(SELECT oip.IP as IP FROM OFFICE_IPS oip, OFFICE_GROUP og WHERE og.OFFICE_GROUP_ID = oip.OFFICE_GROUP_ID
AND og.MODULES like '%2%' lIMIT 1) AS FAQ,
(SELECT oip.IP as IP FROM OFFICE_IPS oip, OFFICE_GROUP og WHERE og.OFFICE_GROUP_ID = oip.OFFICE_GROUP_ID
AND og.GRP_LIMIT like '%1%' lIMIT 1) AS DEV_MODE,
(SELECT oip.IP as IP FROM OFFICE_IPS oip, OFFICE_GROUP og WHERE og.OFFICE_GROUP_ID = oip.OFFICE_GROUP_ID
AND og.GRP_LIMIT like '%2%' lIMIT 1) AS META_API,
(SELECT oip.IP as IP FROM OFFICE_IPS oip, OFFICE_GROUP og WHERE og.OFFICE_GROUP_ID = oip.OFFICE_GROUP_ID
AND og.GRP_LIMIT like '%3%' lIMIT 1) AS TRADING_SIGNAL

但是如果我想获取多行怎么办,我的意思是子查询返回多行。

在上面的查询中,如果我删除“...LIMIT 1”,则会出现如下错误#1242 - 子查询返回多于 1 行

任何人,请帮助我。

最佳答案

您应该在顶级查询的 FROM 部分而不是 SELECT 中执行子查询。尝试这样做

SELECT seminar, faq, dev_mode, meta_api, trading_signal 
FROM (subselect) as seminars_table, (subselect) as faq_table....
WHERE join_contition_1 and join_condition_1;

子选择需要包含连接列。

关于mysql - 从表中获取符合条件的多条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18074435/

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