该查询有效,但只给出了1985年的值。如何添加无限年(1985-2014年)
use baseball;
SELECT CAST(tf.franchname AS CHAR(20)), s.yearID, s.lgid, AVG(s.salary)
FROM salaries s, teams t, teamsfranchises tf
WHERE s.teamID = t.teamID AND
t.franchID = tf.franchID AND
s.yearID = 1985 AND
(s.lgid='AL' OR s.lgid='NL') GROUP BY tf.franchname, s.yearID, s.lgid order BY
s.yearID;发布于 2015-10-21 06:39:02
select cast(tf.franchname as char(20)), s.yearID, s.lgid, avg(s.salary)
from salaries s, teams t, teamsfranchises tf
where s.teamID = t.teamID and
t.franchID = tf.franchID and
(s.yearID between 1985 and 2014 )and
(s.lgid='AL' OR s.lgid='NL')
group by tf.franchname, s.yearID, s.lgid
order by s.yearID;发布于 2015-10-21 06:38:08
你可以用在两者之间。
您的where子句应该如下所示
(s.yearID BETWEEN 1985 AND 2014) and或者,您可以使用<和>运算符:
(s.yearID >= 1984 and <= 2014)如果,由于任何原因,你没有连续的年限(你只想要5年)。IN也可以是一种选择:
s.yearID IN (1984, 1991, 1996, 2001, 2006) 发布于 2015-10-21 06:41:36
您的查询在and s.yearID = 1985年有一个条件筛选,您可能希望使用关键字BETWEEN更改它,或者根据需要完全删除它。
https://stackoverflow.com/questions/33252470
复制相似问题