gpt4 book ai didi

Mysql 查询结合 join、group by、having 和 order by 子句

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

$date = $this->db->select('crv.date')
->from('commodities com')
->where('com.id = ' . $row->id)
->join('curves crv', 'com.curve_id = crv.profile_id', 'left')
->group_by('crv.date')
->having('COUNT(DISTINCT crv.job_id) = ' . $nr_commodities)
->order_by('crv.date DESC')
->limit(1)
->get()->row();

我需要在 mysql 中转换上述查询:

我尝试了以下方法。但出现一些语法错误。任何帮助将不胜感激。

select crv.date
from commodities com
where com.id = 100
left join curves crv on com.curve_id = crv.profile_id
group by crv.date
having COUNT(DISTINCT crv.job_id) = 4
order by crv.date DESC
limit 1

最佳答案

使用,

select crv.date
from commodities com
left join curves crv on com.curve_id = crv.profile_id
where com.id = 100
group by crv.date
having COUNT(DISTINCT crv.job_id) = 4
order by crv.date DESC
limit 1

关于Mysql 查询结合 join、group by、having 和 order by 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52115909/

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