Is it possible to use two parameters in HAVING clause using MAX? Or I need to create some variable? The problem is that I have two columns: date_id (int) and period_time (time). The task is to filter the table using MAX value in these two columns
When I had one parametr, I used code
SELECT PlotsID date_id period_time fieldID FieldName
FROM data_base
WHERE EXISTS
(SELECT 1 AS Expr1 FROM data_base AS t2 WHERE PlotsID=data_base.PlotsID
GROUP BY PlotsID HAVING (data_base.date_id =MAX(date_id) ))
But I understand, that I need to group and filter this very big table (over 1 mln lines of data) with both date_id and period_time
If the table is not too large you can simply use a subquery in the WHERE clause(test1 is an example table):
Select *
from test1
where period_time= ( Select max(period_time) from test1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.