gpt4 book ai didi

mysql - 如何在 Mysql 中使用 where 子句中的 Max counted id 作为参数

转载 作者:行者123 更新时间:2023-11-28 23:30:58 24 4
gpt4 key购买 nike

这里是返回 TraineeID 的第一个查询,它按计数取最大值。我需要在第二个查询中使用此 TraineeID 作为 where 子句中的参数。有什么办法可以做到这一点。提前谢谢你。

查询 1:

SELECT TraineeID, COUNT(TraineeID) as maxfinger 
FROM tbl_raw_attendance WHERE date(CreatedTime)='2016-04-13'
GROUP by TraineeID ORDER by maxfinger DESC
LIMIT 1

查询 2:

SELECT @n := @n + 1 RowNumber, t.*
FROM (select @n:=0) initvars, tbl_raw_attendance t
WHERE date(t.CreatedTime)='2016-04-13'

最佳答案

您可以使用子查询来完成:

SELECT @n := @n + 1 RowNumber, t.*
FROM (select @n:=0) initvars, tbl_raw_attendance t
WHERE date(t.CreatedTime)='2016-04-13'
AND t.TraineeID = (SELECT TraineeID FROM tbl_raw_attendance
WHERE date(CreatedTime)='2016-04-13'
GROUP by TraineeID ORDER by COUNT(TraineeID) DESC
LIMIT 1 )

关于mysql - 如何在 Mysql 中使用 where 子句中的 Max counted id 作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37373022/

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