select plan from table2 where id= select id from table1 where card=''
1、创建测试表; create table company(companyId number, companyName varchar2(20), contacts varchar2(20)); create table users(userId number, companyId number, userName varchar2(20), userAge number, address varchar2(20)); 2、插入测
in的效率是很低的,所以脚本会超时可以这么写selecta.*fromnewsa,(selecttop10newsidfromT_commentgroupbynewsidorderbycount(*)desc)bwherea.id=b.newsid
select a1 col1,a2 col2,a3 col3 from a where (a1,a2,a3) in(select b1,b2,b3 from b)unionselect b1 col1,b2 col2,b3 col3 from b where (b1,b2,b3) not in(select a1,a2,a3 from a)
select * from news where id in ( select top 10 newsid from T_comment order by count(newid) desc) 这样试试呢?
1. select * from a inner join b on a.bid=b.id inner jion c on a.cid=c.id2. select * from a,b,c where a.bid=b.id and a.cid=c.id1. 如果你是完成两个表的关联,那直接查询就可以了;2. 如果你要完成一个表同时查询,就可以使用给表起别名的办法.3. 两个不同的表的关联查询如下:select * from a,b where 条件4. 同一个表的关联查询:select * from a A,where a.*=A.*
如果你想用一条查询实现,先union,作为select子查询 再用select 查询,以下是我写的,但是没有数据库,思路就是这样的.如果报错你调一下,不行的话,你就把库里的这两个表给我.我调好了.再给你 select 销售单号, 总计金额,(select
with a as (select 1 as id, 2 as yuefen, 20 as jixiao union select 2 as id, 2 as yuefen, 20 as jixiao union select 2 as id, 3 as yuefen, 30 as jixiao union select 2 as id, 4 as yuefen, 40 as jixiao), b as (select 1 as id union select 2 as id union select 3 as id)
select * from cj join kc on cj.kcdh=kc.kcdh--就这么简单.这样保证两个表的数据都能查出来.--inner join内连接将会过滤掉不存在关联的数据的.
select A.MEDIID,B.PRICEfrom A,Bwhere a.MEDIID=B.MEDIID