我有一个数据库表,用于保存教育经历。它有4个属性。
- userId(与User表相关的外键)
- beginDay(入学时间)
- endDay(毕业时间)
- 学校(学校名称)
现在我有一个userId,我想根据userId选择上次的教育经历。
如何写hql查询?
我写了
select * from education where userId = 100 and beginDay = max(beginDay)
但是查询错误。控制台输出分组功能使用无效。
最佳答案
为此只需使用此查询:
SELECT * FROM education WHERE userId = 100 ORDER BY beginDay DESC LIMIT 1
关于mysql - 如何编写 HQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33215179/