select trainid from station where name =‘北京”
interstct
select trainid from station where name =”上海”
是不是这个语句只能在两张表下用,一张是用不了的这个关联
假如能的话mysql中又怎么写
interstct
select trainid from station where name =”上海”
是不是这个语句只能在两张表下用,一张是用不了的这个关联
假如能的话mysql中又怎么写
解决方案
40
-- 刚刚理解错了 mysql> create table test(id int, name varchar(10), trainid int); Query OK, 0 rows affected (0.01 sec) mysql> insert into test values(1,"北京",1); Query OK, 1 row affected (0.00 sec) mysql> insert into test values(2,"天津",1); Query OK, 1 row affected (0.00 sec) mysql> insert into test values(3,"北京",2); Query OK, 1 row affected (0.00 sec) mysql> insert into test values(4,"上海",2); Query OK, 1 row affected (0.00 sec) mysql> mysql> mysql> select trainid from test where name in ("北京","上海") -> group by trainid having count(*) = 2 ; +--+ | trainid | +--+ | 2 | +--+ 1 row in set (0.00 sec) mysql> mysql> drop table test ; Query OK, 0 rows affected (0.00 sec) mysql>