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

 ·设计一个类的问题    »显示摘要«
    摘要: 设计一个类方法,接受三个int数,将他们升序输出,不能用数组。 ......
    摘要: 我在本机上做了一个程序,后面是sql,但这个后台数据库不在本机上,而是安装在另外一台电脑上。 我该如何让我这个程序连接另外那台电脑的sql上呢? ......


求一SQL语句,为一个表添加一个临时编号

create   table   test(clothid   varchar(10),number   varchar(10),bagid   varchar(10))  
  insert   into   test  
  select   11-11,56,1  
  union   all   select   11-12-1,45,1  
  union   all   select   11-12-2,46,1  
  union   all   select   11-12-3,50,2  
  union   all   select   11-13-1,60,2  
  union   all   select   11-13-2,32,2  
  union   all   select   11-14,34,3  
  union   all   select   11-15-1,45,3  
  union   all   select   11-15-2,52,3  
  结果如下:  
  id   number   bagid     clothid                                    
  1     56       1 11-11  
  2     45       1 11-12-1  
  3     46               1 11-12-2  
  1     50       2 11-12-3  
  2     60       2 11-13-1  
  3     32       2 11-13-2  
  1     34       3 11-14  
  2     45       3 11-15-1    
  3     52       3 11-15-2  
   
 

NO.1   作者: zjcxc

create   table   test(clothid   varchar(10),number   varchar(10),bagid   varchar(10))  
  insert   into   test  
  select   11-11,56,1  
  union   all   select   11-12-1,45,1  
  union   all   select   11-12-2,46,1  
  union   all   select   11-12-3,50,2  
  union   all   select   11-13-1,60,2  
  union   all   select   11-13-2,32,2  
  union   all   select   11-14,34,3  
  union   all   select   11-15-1,45,3  
  union   all   select   11-15-2,52,3  
  go  
   
  select   id=(select   count(*)   from   test   where   clothid<=a.clothid),  
  number,bagid,clothid  
  from   test   a  
  order   by   id  
  go  
   
  drop   table   test  
   
  /*=--结果  
   
  id                     number           bagid             clothid          
  -----------   ----------   ----------   ----------    
  1                       56                   1                     11-11  
  2                       45                   1                     11-12-1  
  3                       46                   1                     11-12-2  
  4                       50                   2                     11-12-3  
  5                       60                   2                     11-13-1  
  6                       32                   2                     11-13-2  
  7                       34                   3                     11-14  
  8                       45                   3                     11-15-1  
  9                       52                   3                     11-15-2  
   
   
  --*/

NO.2   作者: xluzhong

select   sid=identity(int,1,1),*   into   #t   from   test  
  select  
  id=(select   count(*)   from   #t   where   bagid=a.bagid   and   sid<=a.sid),  
  number,  
  bagid,  
  clothid  
  from   #t   a  
 

NO.3   作者: hsj20041004

To:   zjcxc(邹建)    
  你是不是看错题了!!!  
  结果如下:  
  id   number   bagid     clothid                                    
  1     56       1 11-11  
  2     45       1 11-12-1  
  3     46               1 11-12-2  
  1     50       2 11-12-3  
  2     60       2 11-13-1  
  3     32       2 11-13-2  
  1     34       3 11-14  
  2     45       3 11-15-1    
  3     52       3 11-15-2

NO.4   作者: xluzhong

create   table   test(clothid   varchar(10),number   varchar(10),bagid   varchar(10))  
  insert   into   test  
  select   11-11,56,1  
  union   all   select   11-12-1,45,1  
  union   all   select   11-12-2,46,1  
  union   all   select   11-12-3,50,2  
  union   all   select   11-13-1,60,2  
  union   all   select   11-13-2,32,2  
  union   all   select   11-14,34,3  
  union   all   select   11-15-1,45,3  
  union   all   select   11-15-2,52,3  
  go  
   
  select   sid=identity(int,1,1),*   into   #t   from   test  
  select  
  id=(select   count(*)   from   #t   where   bagid=a.bagid   and   sid<=a.sid),  
  number,  
  bagid,  
  clothid  
  from   #t   a  
  drop   table   test,#t


    摘要: 向数据库插入一条记录。同时返回该记录的id号。 要怎么做。因为我的数据是这样的。 有一个文件,他有两个下载地址。有一个表file和一个表address 表file和address是一对多关系。 我想在增加一个file时,同时向address写进两个下载地址。主键是file的id编号 请问要怎么写。 我的想法:把资料写进file,同时返回该记录的id号。 然后再根据该id号再把两个下载地址写......
» 本期热门文章:

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