当前位置:首页
开发技术指南» 文章正文
    引言:

 ·不能创建对象    »显示摘要«
    摘要: 我的vs.net2003出大问题了,什么类,什么窗体都创建不了,提示“automation服务器不能创建对象”!昨天还可以的! 这是为什么?有什么解决方法吗????? ......
 ·结束了,    »显示摘要«
    摘要: 和一个同事出来做办事处,就是那种独立核算的那种,本来业绩个人觉得还算可以,而且后面有几个很有发展钱途的客户,但是因为同事刚刚结婚家里人说三道四,结果上个月人家就打算撤退了,后来因为来了几个单,所以他决定在留下来,把九月份做完再走,九月5号千翻努力把客户做下来了,收了款还有很多收尾工作没有做,人家突然在六号下午提出不做了,说什么什么,当天晚上房东就过来收房租,郁闷的一踏糊涂,总不能和房东说立......


求一SQL语句

a表    
  cardno     isdown     available   id  
  1000 0 0     1  
  1000 1 0     2  
  1000 1 1     3  
  1000 0 1     4  
  1111 1 1     5  
  2222 0 0     6  
  2222 0 0     7  
  3333 0 0     8  
  3333 0 1     9  
   
  b表  
  cardno   xx   id  
  1000 xx 1  
  1111 xx 2  
  2222 xx 3  
   
  结果  
  cardno   id  
  1000         3  
  1111 5  
  2222 6  
  3333 8  
   
   
  A表中   cardno   可能重复  
   
  结果为A表中所有的记录  
  条件:  
  cardno相同的只取一条,取哪一条根据下面的规则  
  如果A表中   isdown   =1   available   =1   那么得到a表中的ID(如cardno   =1000   则得到ID=3         1111-->5,)  
  否则得到a表中ID的最小值   (如2222-->6,3333-->8)

NO.1   作者: libin_ftsafe

--生成测试数据  
  create   table   #a(cardno   int,isdown   int,available   int,id   int)  
  insert   into   #a   select   1000,0,0,1  
  insert   into   #a   select   1000,1,0,2  
  insert   into   #a   select   1000,1,1,3  
  insert   into   #a   select   1000,0,1,4  
  insert   into   #a   select   1111,1,1,5  
  insert   into   #a   select   2222,0,0,6  
  insert   into   #a   select   2222,0,0,7  
  insert   into   #a   select   3333,0,0,8  
  insert   into   #a   select   3333,0,1,9  
   
   
  --执行查询  
  select  
          t.cardno,t.id  
  from  
          #a   t  
  where  
          (t.isdown   =   1    
            and    
            t.available   =   1  
            and  
            exists(select   1   from   #a   where   cardno=a.cardno   and   isdown=1   and   available=1))  
          or  
          (not   exists(select   1   from   #a   where   cardno=a.cardno   and   isdown=1   and   available=1))  
            and  
            not   exists(select   1   from   #a   where   cardno=a.cardno   and   id   <   a.id))  
   
   
  --输出结果  
  /*  
  cardno     id  
  ------     -----  
  1000         3  
  1111 5  
  2222 6  
  3333 8  
  */

NO.2   作者: lizhaogui

create   table   #a(cardno   int,isdown   int,available   int,id   int)  
  insert   into   #a   select   1000,0,0,1  
  insert   into   #a   select   1000,1,0,2  
  insert   into   #a   select   1000,1,1,3  
  insert   into   #a   select   1000,0,1,4  
  insert   into   #a   select   1111,1,1,5  
  insert   into   #a   select   2222,0,0,6  
  insert   into   #a   select   2222,0,0,7  
  insert   into   #a   select   3333,0,0,8  
  insert   into   #a   select   3333,0,1,9  
   
  create   table   b(cardno   int,id   int)  
  insert   into   b   select   1000,1  
  insert   into   b   select   1111,5  
  insert   into   b   select   2222,6  
  insert   into   b   select   3333,8  
   
   
  --语句  
  select   a.cardno,a.id  
  from   a   ,b  
  where   isdown=1   and   available=1   and   a.cardno=b.cardno  
  union  
  select   a.cardno   ,min(a.id)  
  from   a,b  
  where   (isdown<>1   or   available<>1)  
  and   a.cardno   not   in(select   a.cardno   from   a,b   where   isdown=1   and   available=1   and   a.cardno=b.cardno)  
  group   by   a.cardno  
  order   by   a.cardno  
  结果:  
   
  1000 3  
  1111 5  
  2222 6  
  3333 8  
   
   
   
 


    摘要: 请发到:xck_01@163.com 收到马上给分,不够再加!谢谢各位赐教! ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE