delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
字段下的值不固定的查询 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiDB/html/delphi_20061222093859171.html
我有一个这样的表    
  标号     层号       数值       hs  
  1           A             0.2         ch  
  2           B             0.3         cb  
                                          cn  
                                          ch  
                                          cf  
                                          cn  
  我想实现这样一个查询语句,查询后的结果如下表  
  标号     层号             hs  
  1           A                   ch  
                                  ch  
  2           B                   cb  
                                  cn  
                                  cn  
                                  cf  
  就是把   hs中有相同值的写到一起(空值的不要),但这个字段下的值有可能还只有一个值,所以只要把   这一个值查询出来就行了   也就是这个字段下的值是不固定的  
   
  我应如何实现这条查询语句,是不是应该把hs字段的值写到某个文件中  
  然后在查询   比较啊!  
   
                             
                             
                           
 

select   标号,     层号,           hs  
  from   表    
  order   by   hs,   层号,   标号

select   标号,     层号,           hs  
  from   表    
  where   hs   is   not   null  
  order   by   hs,   层号,   标号  
 

group   by    
  分组问题  
   
 

select   *  
  from   表    
  where   hs   is   not   null  
  order   by   层号,   标号  
  group   by   hs  
   
 

为什么这样查询出来的只是一条啊   !!!!  
  空值的也会查询出来啊  
  如果hs   只有一个值cn    
  hs  
  cn  
  cn  
  cn  
  空值  
  cn  
  查询出来的就是下面这样了  
  hs  
  cn  
  空值  
   
   
 

select   *  
  from   a   where   hs   is   not   null  
  order   by   hs  
 

象上面那样是满足了但  
  这样把hs   为空值的也   查询出来了啊    
  不要空值啊!!!where   hs   is   not   null   这里已经限制了怎么会这样   啊

where   hs   is   not   null   and   hs<>''

怎么会呢,我亲自试的,是不是你什么地方弄错了  
 

where   hs   is   not   null   and   hs<>''  
  这样写会出错的!  
  !  
  007     我就是象你给我的那样写  
  select   *  
  from   a   where   hs   is   not   null  
  order   by   hs  
  我在看看  
 

where     hs     is     not     null     and     hs     <     >''''    
  写成这样就好了   !!!  
   
  可以了  
  谢谢俩位了   啊  
     
 

好了   给你们分了  
  谢谢

posted on 2008-12-11 10:09 delphi2007 阅读(92) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。