我目前是 SQL 语言的新手,我正在努力理解如何从下表中检索正确的信息:
职员表
+------+----------+---------+-----------------+------+------+
| s_id | initials | s_name | pos | qual | d_id |
+------+----------+---------+-----------------+------+------+
| AA | A. | Tom | Lecturer | PhD | RELI |
| BBB | J.J. | Jason | Senior Lecturer | PhD | RELI |
| CCC | B.A. | Andy | Senior Lecturer | PhD | BIOL |
| DD | M. | Mark | Professor | PhD | BIOL |
| EE | W. | Alen | Professor | BA | BIOL |
+------+----------+---------+-----------------+------+------+
研究表
+------+-------+------------+-----------+
| s_id | r_id | str_date | fin_date |
+------+-------+------------+-----------+
| BBB | RESH1 | 1990 | 1998 |
| BBB | RESH2 | 1980 | 1985 |
| DD | RESH4 | 1995 | 1999 |
| AA | RESH4 | 1992 | 1999 |
| CCC | RESH8 | 1989 | 1994 |
| EE | RESH5 | 1988 | 1989 |
+------+-------+------------+-----------+
我正在尝试创建一个新表,其中将包含员工 s_name 以及每个人做了多少不同的研究。
到目前为止我所拥有的是
select distinct s.s_name, count(r.s_id)
from staff s
inner join research r
on s.s_id = r.s_id
where s.s_id = r.s_id;
我的结果是,
+---------+---------------+
| s_name | count(r.s_id) |
+---------+---------------+
| Jason | 6 |
+---------+---------------+
我做错了什么?
提前致谢。