delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
求一条sql语句~```` Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiDB/html/delphi_20061220134634201.html
我有三个表   aa.bdf     bb.dbf       cc.dbf  
  aa.dbf中的字段  
  jh             yc         yx         yxh  
  name1       ch         0.2       101.1  
   
  bb.dbf中的字段  
  jh             jd1           jd2  
  name1       100.1       200.1  
   
  cc.dbf中的字段  
  jh           年月               hs  
  name1     20061011       0.3  
   
  我想完成这样的查询:  
  我想首先为表aa添加一个字段sk,判断aa表中的yxh   字段的值   是否在   bb表中的   jd1   和jd2   之间   如果在sk的值就写   K   ,     不在就为空  
  我已经把   年月这个字段的值都添加到combobox   中  
  先在combobox中选择有个年月  
  找aa表中sk     字段的值为K的   和aa表中yx>=0.4   的   和cc表中hs   >=30%的  
   
  如何为aa表添加那个sk字段   如何写最后的那条查询语句  
 

--增加字段sk  
  alter   table   aa   add   sk   varchar(4)   null  
  go  
  --更新字段sk  
  update   aa   set   sk=   'K'   from   aa   a,bb   b   where   a.jb   =     b.jh   and   a.yxh   between   b.jd1   and   b.jd2  
  go  
  --查询  
  select   *   from   aa   a,cc   b   where   a.jh   =b.jh   and   a.sk='K'   and   a.yx>=0.4   and   c.hs>=0.3   and   c.年月=combobox中的值  
   
  在DELPHI中有个专门选择日期的控件DateTimePicker,比combobox更好

select   jh,yc,yx,yhx   from   (select   aa.*,   'sk'   =     case   when   aa.yxh   >=   bb.jd1   and   aa.yxh<=bb.jd2   then   'K',   else   ''   from   aa,   bb   where   aa.jh   =   bb.jh)   XXX,   cc   where   yx>=0.4   and   sk='k'   and   hs>=0.3

select   jh,yc,yx,yhx   from   (select   aa.*,   'sk'   =   case   when   aa.yxh   >=   bb.jd1   and   aa.yxh<=bb.jd2   then   'K',   else   ''   end   from   aa,   bb   where   aa.jh   =   bb.jh)   XXX,   cc   where   yx>=0.4   and   sk='k'   and   hs>=0.3  
  修改一下,少了个end

posted on 2009-02-19 16:58 delphi2007 阅读(90) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。