MySQL多表关联⼀对多查询实现取最新⼀条数据的⽅法⽰例
照片img是什么格式
299篇(以后博客篇数写到正⽂⾥⾯了)
可以完全参考这个⽅法,点击链接
下⾯的sql可以实现,主表关联详情表,详情表需要查两次
SELECT
cr.id,
oi.industry,
oi.nature_tax
FROMangular合并不同分组
customer AS cr
LEFT JOIN (
SELECT a.industry, a.nature_tax, a.customer_id, a.create_time FROM order_info AS a
LEFT JOIN (
SELECT MAX(id) AS id, customer_id FROM order_info GROUP BY customer_id
) AS b ON a.customer_id = b.customer_id
WHERE a.id = b.id
) AS oi ON oi.customer_id = cr.id;
下⾯是我⾃⼰个的sql
SELECT a1.id,
jdbc代码a1.value_submit,
b1.id,
b1.purchase_apply_no,代码vbs删除文件
b1.department_id ,
b1.budget_class_id,
b1.project_no,
FROM t_occupy AS a1
JOIN
css怎么设置超链接样式(SELECT a.*
FROM t_occupy_detail AS a
LEFT JOIN
(SELECT max(id) AS id,
occupy_id
FROM t_occupy_detail
GROUP BY  occupy_id ) AS b
upy_id = b.occupy_id
WHERE a.id = b.id ) AS b1mysql语句多表查询
ON a1.id = b1.occupy_id
st_type = a1.status
able=1
able=1

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。