SQL数据库基础讲解

分享到:

2014-01-25 21:10:12

4格式:select 字段名 from 表名 where 条件
4例:查询数据库中所有10月份类别为01的凭证
4select * from gl_accvouch where iperiod=10 and csign=‘01’
4*代表所有字段
4GL_ACCVOUCH为凭证表名
4IPERIOD 是月
4CSIGN是凭证类别
4查某几个字段可以把*换成字段名
4可以用BETWEEN AND 来规定日期范围
4可以用IN()来规定条件范围
4在总帐中查询所有客户10月20日到11月20日的应收帐款发生额及余额,按客户编码排序
4在总帐中查询所有客户10月20日到11月20日的应收帐款发生额及余额,按客户编码排序
4Sum为求和,sumgroup by 连用是分组求和,如果不用group by 就是把所有记录加成一个数
4order by 为排序 order by +字段名就是按某一字段排序
4两个表关联查询
4格式:select 字段名 from 表名a join 表名 b on 关联条件 where 查询条件
4例:select b.ccusname客户名称,b.ccusid客户编码,a.sum(md)借方金额,a.sum(mc)贷方金额 from gl_accvouch a inner join customer b on a.ccus_id=b.ccusid where a.ddate between 2002-10-20 and 2002-11-20 and a.ccode=1131 group by b.ccusid order by b.ccusid
4Inner join 内连接 只显示查询字段
4left join 左连接 两张表的字段同时显示
4select a.citem_id,b.cinvstd,  sum(case when cendd_c='借' then me else 0 end)-sum(case when cendd_c='贷' then me else 0 end) as je,  sum(case when cendd_c='借' then ne_s else 0 end)-  sum(case when cendd_c='贷' then ne_s else 0 end) as ne_s,  sum(b.iinvsprice/1.17) as wsdjinto ch_temp  from gl_accass a join inventory b   on a.citem_id=b.cinvcode where iperiod='10' and citem_id is not null and ccode='124101' and me<>0group by a.citem_id,b.cinvstd
4case when 条件 then 结果 else 另一结果.如果where 条件里只能加入一种选择的话,以上语句就十分有用了,它可以帮助我们分类统计数据
select 字段名 into 临时表名 from 来源表名 where 条件,如果我们的数据要从好多表中提取,那用生成临时表的方法会使我们少绕很多弯路
4跨计算机取数
4select a.ccode  from gl_accass a left join


 [192.1.5.252].[haier_office].

[dbo].b_queryparam b on a.ccode=b.ccode where

b.ccode is  null group by a.ccode
4sp_serveroption '192.1.5.252','data access','true' 
声明:此篇为用友服务中心文章,转载请标明出处链接:
  • 相关文章
  • 热门下载
  • 数据修复
  • 热门标签
合作伙伴