惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
D
Docker
云风的 BLOG
云风的 BLOG
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog
GbyAI
GbyAI
T
Tailwind CSS Blog
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
C
Check Point Blog
I
InfoQ
Microsoft Azure Blog
Microsoft Azure Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志
小众软件
小众软件
N
Netflix TechBlog - Medium
B
Blog RSS Feed
腾讯CDC
aimingoo的专栏
aimingoo的专栏

博客园 - 杨林

IIs一些配置 扩大传输限制 exchange file 关于VS2005 无法使用切换到设计视图的解决方法 使用ASP.Net Forms模式实现WebService身份验证 SendEmail - 杨林 - 博客园 web导出excel格式问题 Form身份验证 - 杨林 - 博客园 在ASP.NET 2.0中使用Membership 设计模式之状态模式 sqlserver2005学习笔记 共享内存进程之间 ComparaCarAdapter sql 利用索引优化性能 SQL 2005新增的几个函数之学习 Thread pool web service web service 多线程分析 js Function.call
sql T
杨林 · 2008-01-18 · via 博客园 - 杨林

select * from company as c1 inner join company c2 on c1.companyid=c2.companyid where 


  create   table   [work]([Id]   int,TypeId   int,[Name]   varchar(10))  
  insert   into   [work]   select   1,1,'3232'  
  insert   into   [work]   select   2,3,'grtr'  
  insert   into   [work]   select   3,2,'gggr'  
  insert   into   [work]   select   4,2,'yy'  
  insert   into   [work]   select   5,1,'zz'  
  insert   into   [work]   select   6,3,'g33rtr'  
 insert   into   [work]   select   7,3,'g33rtr'  
 insert   into   [work]   select   8,2,'yy'  

  create   table   Type([Id]   int,TypeNum   int)  
  insert   into   Type   select   1,3  
  insert   into   Type   select   2,1  
  insert   into   Type   select   3,2  
   

select * from work
select distinct typeid into liny  from work


select * from work  as w1  where id in (
select top 2 id from work w2 where w1.typeid=w2.typeid order by id) order by typeid 

  declare   @sql   varchar(1000)  
  set   @sql=''  
  select   @sql=@sql+'   select   TOP   '+cast(TypeNum   as   varchar)+'   b.[id],b.[typeid],b.[name]   from   type   a,work   b   where   a.[id]=b.[typeid]   and   a.id='+cast([id]   as   varchar)+'   union   all'   from   type  
  set   @sql=left(@sql,len(@sql)-11)  
  print @sql
  exec(@sql)

  declare   @sql   varchar(1000)  
  set   @sql=''  
  select   @sql=@sql+'   select   TOP   '+cast(TypeNum   as   varchar)+'   b.[id],b.[typeid],b.[name]   from   type   a,work   b   where   a.[id]=b.[typeid]   and   a.id='+cast([id]   as   varchar)+'   union   all'   from   type  
  set   @sql=left(@sql,len(@sql)-11)  
  print @sql
  exec(@sql)