--ÐÐÁÐת»» ÐÐתÁÐ
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 SERVER2000ÆóÒµ°æ½øÐÐË«»úÈȱ¸µÄÒ»¸öÖ÷Òª½â¾ö·½°¸£¬ÆäÔÀí±È½Ï¼òµ¥£¬ÊµÏÖÒ²±È½Ï·½±ã£¬Ö»ÊÇÓÉÓÚºÍWindowsÖ®¼ä´í×Û¸´ÔӵĹØϵ£¬µ¼ÖÂÉèÖÃÆðÀ´Óв»ÉÙÀ§ÄÑ£¬³öÏÖÎÊÌâÒ²²»ÈÝÒ×Õï¶Ï¡£
1.ʵÏÖ¸ÅÊö
*Ë«»úÈȱ¸Õë¶ÔµÄÊǾßÌåµÄij¸öÊý¾Ý¿â¶ø²»ÊÇÕû¸ö·þÎñÆ÷
Ë«» ......
ÔÚ×ösqlÌâʱ£¬ÎÒÃÇ×îÅÂÓöµ½Ìõ¼þ¸´ÔӵIJéѯÓï¾ä£¬ÒòΪ´ó¶àʱºòÐèÒªÁ½Èý¸ö×Ó²éѯÀ´ÊµÏÖ£¬
¶ø´ó¶àÊýͬѧ£¬¿ÉÒÔ˵¶¼±È½ÏÅÂ×Ó²éѯµÄ£¬ÒÔÇ°ÎÒÒ²±»ÕâЩÌâĿŪµÄÔÆÀïÎíÀïµÄ£¬
²»¹ý×ö¶àÁËÕâÀàµÄÌâÄ¿ºó·¢ÏÖ£¬ÆäʵҲÓÐÒ»¶¨¹æÂÉ£¬ÎÒÃÇ¿ÉÒÔ×ܽáÒ»Ì×ÊʺÏ×Ô¼ºµÄ·½·¨À´´¦Àí£¬
ÏÂÃæʱÎÒ¶Ô¸ÃÀàÌâÄ¿µÄ´¦Àí·½·¨£º
ÓйºÎï±íÈçÏ£º
ÌâÄ¿£º ²é ......