
db2
lanzongjie198200
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
根据相同的key合并值(行转列)
--删除测试表 --drop table test; --创建测试表 create table test (fcode varchar(10),fname varchar(20)); --插入测试数据 insert into test(fcode, fname) values('1001', 'A1'),('1001', 'B1'),('1001', 'C1'),('1002', 'A...2010-12-17 11:35:23 · 265 阅读 · 0 评论 -
db2常用函数整理
1.coalesce(字段名,空的默认值): coalesce函数会依次检查输入的参数,返回第一个不是NULL的参数,只有当传入COALESCE函数的所有的参数都是NULL的时候,函数才会返回NULL。 2.year(日期字段):获取年份; month; day 3.将字符串转换成年月日:date(“2010-10-10 10:10:10”) 4.将字符串转换成时分秒:time(“2010...2011-03-17 17:11:07 · 281 阅读 · 0 评论 -
db2常用命令整理
连接数据库:db2 connect to 数据库名 user 用户名 using 密码 启动实例:db2start 停止实例:db2stop force (force表示强制停止实例) 创建实例:db2icrt 实例名 删除实例:db2idrop -f 实例名 查询数据库的配置:db2 GET DB CFG FOR 数据库名称 查询数据库的日志配置:db2 GET DB CFG FOR...2011-03-17 17:08:49 · 165 阅读 · 0 评论 -
合并相同班级的科目分数(行转列)
--drop table score; create table score ( banji integer, --班级 kemu varchar(10), --科目 fengshu integer --分数 ) ; insert into score values (1, '语文', 8800), (1, '数学', 8...2011-03-17 15:56:47 · 253 阅读 · 0 评论 -
根据子节点的金额向上汇总所有父节点的金额
with test(fid, fname, fparentid, fmoney) as ( values('01', 'test01', '0', 0) union values('0101', 'test0101', '01', 0) union values('010101', 'test010101', '0101', 10) union value...2010-12-21 17:14:34 · 833 阅读 · 0 评论 -
根据子节点查找所有父节点
-- 方法一:通过父节点关联(递归) with test(fid, fname, fparentid) as ( values('01', 'test01', '0') union values('0101', 'test0101', '01') union values('010101', 'test010101', '0101') union val...2010-12-21 16:53:35 · 1570 阅读 · 0 评论 -
获取树型节点的全名称
-- 获取树型节点的全名称:父节点名称 + ... + 当前节点名称 with test(fid, fname, fparentid) as ( -- 结果1, 见附图 values('01', 'test01', '0') union values('0101', 'test0101', '01') union values('010101', 'test0...2010-12-21 16:23:44 · 877 阅读 · 0 评论 -
存储过程-根据类型合并相邻的票据
--drop table test; -- 保存缓存数据的表 create table test ( ftype varchar(32) , fstart_serial integer , fstart_code varchar(18) , fend_serial integer , fend_code varchar(18) ) -- 测试数据 ...2010-12-21 10:05:57 · 125 阅读 · 0 评论 -
列换行
--方法1:通过union或union all转换 with tdata as ( select * from table( values('张三', 90.5, 88.5, 95.5, 100), ('李四', 90.5, 88.5, 95.5, 0) ) as t(fname, fmoney8, fmoney9, fmoney10, fmoney11) ) select fname...2010-12-17 16:12:13 · 143 阅读 · 0 评论 -
自定义函数-根据相同的key合并值
--删除测试表 --drop table test; --创建测试表 create table test (fcode varchar(10),fname varchar(20)); --删除临时表 --drop table temp; --创建临时表 create table temp(fkey varchar(10),fvalue varchar(100)); ...2010-12-17 11:42:58 · 149 阅读 · 0 评论 -
统计重复记录having
select fname,count(*) as fnum from table group by fname having count(*) > 12011-03-17 17:12:47 · 237 阅读 · 0 评论