易截截图软件、单文件、免安装、纯绿色、仅160KB

一些SQL 和 存储过程

 --行列转换 行转列
DROP TABLE t_change_lc;
CREATE TABLE t_change_lc (card_code VARCHAR2(3), q NUMBER, bal NUMBER);
INSERT INTO t_change_lc
SELECT '001' card_code, ROWNUM q, trunc(dbms_random.VALUE * 100) bal from dual CONNECT BY ROWNUM <= 4
UNION
SELECT '002' card_code, ROWNUM q, trunc(dbms_random.VALUE * 100) bal from dual CONNECT BY ROWNUM <= 4;
SELECT * from t_change_lc;
SELECT a.card_code,
       SUM(decode(a.q, 1, a.bal, 0)) q1,
       SUM(decode(a.q, 2, a.bal, 0)) q2,
       SUM(decode(a.q, 3, a.bal, 0)) q3,
       SUM(decode(a.q, 4, a.bal, 0)) q4
  from t_change_lc a
 GROUP BY a.card_code
 ORDER BY 1;
 
--行列转换 列转行
DROP TABLE t_change_cl;
CREATE TABLE t_change_cl AS
SELECT a.card_code,
       SUM(decode(a.q, 1, a.bal, 0)) q1,
       SUM(decode(a.q, 2, a.bal, 0)) q2,
       SUM(decode(a.q, 3, a.bal, 0)) q3,
       SUM(decode(a.q, 4, a.bal, 0)) q4
  from t_change_lc a
 GROUP BY a.card_code
 ORDER BY 1;
 
SELECT * from t_change_cl;
SELECT t.card_code,
       t.rn q,
       decode(t.rn, 1, t.q1, 2, t.q2, 3, t.q3, 4, t.q4) bal
  from (SELECT a.*, b.rn
          from t_change_cl a,
               (SELECT ROWNUM rn from dual CONNECT BY ROWNUM <= 4) b) t
 ORDER BY 1, 2;
 
--行列转换 行转列 合并
DROP TABLE t_change_lc_comma;
CREATE TABLE t_change_lc_comma AS SELECT card_code,'quarter_'||q AS q from t_change_lc;
SELECT * from t_change_lc_comma;
SELECT t1.card_code, substr(MAX(sys_connect_by_path(t1.q, ';')), 2) q
  from (SELECT a.card_co


相关文档:

远程备份SQL Server 2005数据库

 今天终于把这个问题给解决了:
参考文章:http://blog.csdn.net/long2006sky/archive/2007/04/23/1576583.aspx
实例说明:
           环境:win2k+sqlserver 2K+查询分析器
           SQLSERVER服务实例 ......

Sql Server2005实现远程备份数据库

 
相信大家都在当心数据库的丢失,这也是每个开发者头痛的一件事件,因为正在运行的服务器及数据库也在这台服务器上。如果服务器崩溃,那么所有的数据
都不存在了,就算是你在你的机子上做了备份,那也是没有用的,为什么会这样说主要是因为本机是向互联网公开的,所以出事故的概率就比较高。最终我们可以利
用局域 ......

用sql写小计和合计

select case when b.name is null and c.name is null then '合计' when b.name is null and c.name is not null then '小计' else b.name end as mtrname,
sum(a.number),c.name as cname from x_sell a join x_material b on a.mtr=b.fid join p_organi c on c.fid=a.customer
where a.stime>'2009-10-01'
GROUP B ......

执行SQL取PostgreSQL数据库或表大小

在PostgreSQL8.1.3上可以work
1. 取数据库大小
SELECT pg_size_pretty(pg_database_size('somedatabase')) As fulldbsize
2. 取表大小
SELECT pg_size_pretty(pg_total_relation_size('someschema.sometable')) As fulltblsize, pg_size_pretty(pg_relation_size('someschema.sometable')) As justthetblsize
原贴:
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号