sql 查询

时间:2024-03-13 11:06:59

连续区域取数

 select sid,min(b.eid) as eid from 

    (select  id+2 as sid  from txtTempTable where tc1 like 'Name*') as a,

      (select id as eid  from txtTempTable where tc1='Page') as b 

        where sid<b.eid

       group by sid

                        16,18, 22,23

id        tc1 tc2
16
17
18
22
23

两表对应关联

select aa.sid,aa.eid,
(select top 1 tc2 from txtTempTable where tc1 like "Analyte*" and id>aa.sid-14 and id<aa.eid)
 as xmmc  from   
(
  select sid,min(b.eid) as eid from 
    (select  id+2 as sid  from txtTempTable where tc1 like 'Name*') as a,
      (select id as eid  from txtTempTable where tc1='Page') as b 
        where sid<b.eid
       group by sid
 ) as aa

sid         eid mc
16 18 f01
22 23 f02