以查询作为表的sql语句

基本语法select a.xx,b.yy from a, (select * from m,n) b where a.id=b.id and ...

这种语法可将两次查询或多次查询合并到一次,不用再将上次查询结果id记录再写 where id in (上次查询id)之类。与left jion相似,但本质不同

例如:

select f1.id, f1.nm, f2.zf, f2.gf, f2.df  f3.cnt from JB f1 , td f2,
(
select id, count(id) cnt   from
            (
                 select id   from dy
                 where df<9.85 and not (kf=0 and df=0 and zf=0 ) and
                 id in
                      (
                           select id from DY  group by id  having count(id)<=20
                      )
            )
            group by id having count(id)<=5 order by count(id)
) f3
where 
f1.id =f2.id  and f3.id=f2.id
order by cnt,ds desc

posted on 2017-02-21 12:07  mol1995  阅读(392)  评论(0)    收藏  举报

导航