gpt4 book ai didi

一张表有三个标识符的SQL算法

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:26:55 24 4
gpt4 key购买 nike

这可能真的很容易,但我不知道如何通过一个查询从我的数据库中获取必要的值。只是现在想不通。我将在 CodeIginiter 系统中进行此查询。

表'信息'构造:

CREATE TABLE information (
planid int(11) NOT NULL,
production_nr int(11) NOT NULL,
status int(11) NOT NULL
);

表‘信息’内容:
enter image description here

必要的输出:我想得到(最好 - 只有一个查询,但如果不可能,那么有多个)所有 planid 的位置:所有这个计划 id 的 pruduction_nrs 的状态 >= 3。

在这种情况下,我需要获取这些 planid:2 和 5,因为这些 planid 的所有 production_nrs 中的每一个都具有大于或等于 3 的状态。

最佳答案

select planid, production_nr
from information inf1
where not exists (select 1 from information inf2
where inf1.planid = inf2.planid
and status < 3)

您可以考虑根据需要修改 select 子句(第一行):

  • 添加不同的(如果表 PK 包含状态列)

  • 更改列列表

关于一张表有三个标识符的SQL算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23929652/

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