sql - SQL where 列表中的元组
问题描述
我需要查询帮助,我需要为每年选择持续时间最长的课程名称。我的查询看起来像这样
select *
from courses
where (cyear,duration) IN (
select cyear, max(duration)
from courses
group by cyear)
问题在于它会在以下位置出现以下错误:(cyear,
表达式 de type non booléen spécifiée dans un contexte où une condition est Attendue, près de ','。
解决方案
SQL Server 不支持带有in
. 最接近合理的语法是切换到相关子查询:
select c.*
from courses c
where c.duration = (select max(c2.duration)
from courses c2
where c2.cyear = c.cyear
);
推荐阅读
- autofac - AutoFac 模块未处理
- neo4j - Neo4j:如何在 Neo4j 服务器上安装 APOC?
- reactjs - JEST 组件测试
- javascript - Meteor:为客户端转换 MongoDB 服务器代码
- java - Java 在 Sublime Text 3 中编译
- spring-data-mongodb - Spring Boot 和 Mongo DB:仅获取最新版本的 Document
- python - 如何去除条形图周围的空白
- admin-on-rest - 使用翻译功能时,Polyglot 似乎不起作用
- python - 如何获得一个句子的热编码?
- error-handling - 在 F# 中“合并”有区别的联合?