将此oracle语句转成mysql语句,mysql中没有intersect

MySql 码拜 8年前 (2016-02-07) 933次浏览
select trainid from station where name =‘北京”
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>

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明将此oracle语句转成mysql语句,mysql中没有intersect
喜欢 (0)
[1034331897@qq.com]
分享 (0)