SQL查询同一列两次

兰博萨

我需要根据另一个关系值在同一列中查询不同的值。

表格设置如下:田径ID,meetName,eventName,得分

事件都是一样的,但是有不同的聚会,我的查询需要返回:援助,事件,meetName ='whatever1'的得分,meetname ='whatever2'的得分

我已经尝试了完成此操作的所有基本方法,但无法做到。我终于尝试了

SELECT distinct athleteID, event,
(select score from performances where meetName='Snowflake') as SnowScore,
(select score from performances where meetName='Valentine') as ValScore,
from performances
where event='high jump'

返回:单行子查询返回多个行

我的预期结果将是这样的:

aid, event, SnowScore, ValScore
1 , high jump, 6,  8
2 , high jump, 3,  5
3, high jump, 8, 10
兰博萨

我想补充一点,对于基本(非商业)sql,应该在此处进行自然内部联接。

语法应该是: select * from (subquery1) NIJ (subquery2)

子查询语法:

select athleteID, score as ValScore from performances, NIJ athletes where meet =‘Valentin’ and event=‘beam’

select athleteID, score as SnowScore from performances, NIJ athletes where meet =‘SnowFlake’ and event=‘beam’

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章