gpt4 book ai didi

mysql查询从具有表字段的两个表中获取最后n条记录

转载 作者:行者123 更新时间:2023-11-30 22:54:33 25 4
gpt4 key购买 nike

image1=emp_detail (table),
image2=emp_atnd (table),
image3=result that i get right now,
image4 =expected result's image.

emp_detail table

emp_atnd table

result

expected result

这里我有两个表,第一个是 emp_detail 表,第二个是 emp_atnd 表。最后一张图片是我想要的结果,但现在我使用给定查询得到的结果类似于图片 3。

SELECT `emp_id`,`emp_date`,`first_nm` FROM `emp_atnd`,`emp_detail` WHERE `emp_id` IN (SELECT `id` FROM `emp_detail`)AND YEAR(`emp_date`)=2014 LIMIT 0,4

为什么我没有得到我想要的结果?

最佳答案

SELECT emp_id,emp_date,first_nm FROM emp_atnd JOIN emp_details on emp_id = id WHERE YEAR(emp_date)=2014 LIMIT 0,4

关于mysql查询从具有表字段的两个表中获取最后n条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26988869/

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