Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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 ×óÍâÁ¬½Ó£¬ÓÒÍâÁ¬½Ó£¬È«Á¬½Ó£¬ÄÚÁ¬½Ó

 Áª½ÓÌõ¼þ¿ÉÔÚ   from   »ò   WHERE   ×Ó¾äÖÐÖ¸¶¨£¬½¨ÒéÔÚ   from   ×Ó¾äÖÐÖ¸¶¨Áª½ÓÌõ¼þ¡£WHERE   ºÍ   HAVING   ×Ó¾äÒ²¿ÉÒÔ°üº¬ËÑË÷Ìõ¼þ£¬ÒÔ½øÒ»²½É¸Ñ¡Áª½ÓÌõ¼þËùÑ¡µÄÐС£   
   
Áª½Ó¿É·ÖΪÒÔϼ¸Àࣺ      ......

SQL Server 2000 Êý¾Ý¿âͬ²½

SQL Server 2000 Êý¾Ý¿âͬ²½ÅäÖõÄÔ­Àí
¸´ÖƵĸÅÄî
Microsoft? SQL Server? 2000 µÄ¸´ÖÆÊÇÔÚÊý¾Ý¿âÖ®¼ä¶ÔÊý¾ÝºÍÊý¾Ý¿â¶ÔÏó½øÐи´ÖÆ
ºÍ·Ö·¢²¢½øÐÐͬ²½ÒÔÈ·±£ÆäÒ»ÖÂÐÔµÄÒ»×é¼¼Êõ¡£
ʹÓø´ÖÆ¿ÉÒÔ½«Êý¾Ý·Ö·¢µ½²»Í¬Î»Öã¬Í¨¹ý¾ÖÓòÍø¡¢Ê¹Óò¦ºÅÁ¬½Ó¡¢Í¨¹ý Internet ·Ö
·¢¸øÔ¶³Ì»òÒƶ¯Óû§¡£¸´ÖÆ»¹Äܹ»Ê¹Óû§Ìá¸ßÓ¦ÓóÌÐòÐÔÄÜ ......

sql È¡·´

 update anketo1 set fb = substring('10',fb+1,1) WHERE id =5
ºóÀ´ÎÊÁËBM,BM˵ֱ½ÓÈ¡·´
update anketo1 set fb = ~ fb WHERE id =5
ÎÒ¸æËßÁËBMÓÃsubstringÒ²¿ÉÒÔ.
BM˵:"Õâ¼Ò»ïÀ÷º¦£¬ÕâÒ²ÄÜÏë³ö,ÕâÊôÓÚаÃÅÎ书."
×îºóÓÖÏëµ½ÓÃABSÈ¡¾ø¶ÔÖµÒ²¿ÉÒÔ
update anketo1 set fb = abs(fb-1)
ÎÒ¾õµÃ²»¹ÜÊÇʲôÎ书,ÄÜÖ ......

ÅäÖÃʹÓà SQL ServerÌṩ³ÌÐò ¡£

 ÅäÖÃʹÓà SQL ServerÌṩ³ÌÐò
 <configuration>
  <system.web> <-- ¸ü¸ÄÌṩ³ÌÐòÅäÖ㺠-->
    <membership defaultProvider="AspNetSqlProvider" />
  </system.web>
  <membership> <--ÅäÖÃÌṩ³ÌÐò -->
  <prov ......

ÓÃ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 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ