gpt4 book ai didi

php - 我需要使用 mysql 比较不同行中的两个不同列

转载 作者:行者123 更新时间:2023-11-29 21:04:30 25 4
gpt4 key购买 nike

我需要比较不同行中的两列 l_area 和 d_area 。

如果第1行的l_area等于第2行的d_area,需要输出寄售表结果

下面是我的模型,但它检查同一行

public function return_loads()  
{
$where='d_area=l_area';
$this->db->select('*');
$this->db->from('consignment');
$this->db->where('consignment.status',0);
$this->db->where($where);
$query = $this->db->get();
return $query;
}

最佳答案

我认为您需要加入这里:

SELECT c.*
FROM consignement c
INNER JOIN consignement c2
ON c.d_area = c2.d_area
WHERE c.consignement_status=0
-- AND c2.consignement_status=0

不确定 where 子句的最后一部分,这取决于您的具体用例。这是原始 SQL,但您可以使用 codeIngiter 的 join() 来实现:

public function return_loads()  
{
$where='d_area=l_area';
$this->db->select('c1.*');
$this->db->from('consignment c1');
$this->db->join('consignement c2', 'c1.l_area = c2.d_area', 'inner');
$this->db->where('c1.status',0);
$this->db->where($where); -- use 'c1' instead of 'consignement' in your where clause
$query = $this->db->get();
return $query;
}

您还可以查看this question .

关于php - 我需要使用 mysql 比较不同行中的两个不同列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36941951/

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