Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ͬһ¸ö½»²æ±íµÄ¶¯Ì¬SQLʵÏÖ

DECLARE
 TYPE list IS TABLE OF t_stu.project%TYPE INDEX BY BINARY_INTEGER;
 project_list list;
 v_pro_num NUMBER;
 sql_str VARCHAR(255);
 
t_stu
SID SUBJECT SCORE
1        Êýѧ         99
1        Ó¢Óï         68
1        ·¨ÂÉ         79
2        Êýѧ         92
2        Ó¢Óï         72
2        ·¨ÂÉ         96
ʵÏÖ======
SID
Êýѧ
Ó¢Óï
·¨ÂÉ
1
99
68
79
2
92
72
96
 
DECLARE
 TYPE list IS TABLE OF t_stu.subject%TYPE INDEX BY BINARY_INTEGER;
 subject_list list;
 v_pro_num NUMBER;
 sql_str VARCHAR(255);
BEGIN
 SELECT COUNT(DISTINCT subject) INTO v_pro_num from t_stu;
 sql_str := 'SELECT id ';
 
 FOR v_idx in 1..v_pro_num LOOP
 
  IF v_idx = 1 THEN
  
   SELECT DISTINCT subject INTO subject_list(v_idx) from t_stu WHERE rownum = 1;
   
  ELSE
  
   SELECT subjectINTO subject_list(v_idx)
   from (SELECT DISTINCT subject, rownum row_num from t_stu WHERE rownum < v_idx + 1)
   WHERE row_num = v_idx;
   
  END IF;
  
  sql_str := sql_str || ', SUM(DECODE(subject,''' || subject_list(v_idx) || ''',score,0)) AS ' || subject_list(v_idx);
  
 END LOOP;
 
 sql_str := sql_str || ' from t_stu GROUP BY id';
 DBMS_OUTPUT.PUT_LINE('sql--->' || sql_str);
  
 EXEC IMMEDIATE sql_str;
&


Ïà¹ØÎĵµ£º

SQL Server 2008°¸ÀýÖ®CareGroup Ò½ÁÆ×éÖ¯

CareGroup Ò½ÁÆ×éÖ¯¸ºÔð±£»¤2TB µÄ²¡ÈËÐÅÏ¢ºÍÏà¹ØÊý¾ÝµÄÒþ˽¼°ÍêÕûÐÔ¡£¸Ã×é֯λÓÚ²¨Ê¿¶Ù£¬ÊÇBeth Israel Deaconess ҽѧÖÐÐÄ£¨¹þ·ðҽѧԺµÄ½ÌѧҽԺ£©ÒÔ¼°ÁíÍâÈý¼ÒµØÇøÒ½ÔºµÄĸ¹«Ë¾¡£CareGroup ²ÉÓÃMicrosoft® SQL Server™ 2005£¬½«ÆäÊý¾Ý´æ´¢ÓÚ30¸öʵÀýµÄ390¸öÊý¾Ý¿âÖС£¸Ã×é֯ϣÍû½«Êý¾Ý¿âÉý¼¶µ½SQL Server 200 ......

SQL Server2008°¸ÀýÖ®CyberSavvy ¹«Ë¾

CyberSavvy ¼áÐÅÈí¼þ×Ô¶¯»¯¿ÉÒÔÈÿͻ§ÇáËÉÏíÊÜÉú»î¡£DataPlace ÊǸù«Ë¾µÄÈí¼þ¼´·þÎñ½â¾ö·½°¸£¬Ò²¿É³Æ֮Ϊ“Êý¾Ý¿â¹¤³§”£¬ËüÄܹ»ÈÃÃæÏò¼¼ÊõÒÔ¼°ÃæÏòÉÌÎñµÄÓû§´´½¨²¢ÐÞ¸Ä×Ô¼ºµÄÊý¾Ý¿â£¬¶øCyberSavvy ¹«Ë¾½«Îª¸ÃÊý¾Ý¿âÌṩÍйܷþÎñ¡£Òò´ËCyberSavvy ¹«Ë¾ÐèÒªÅÍʯ°ã¼á¹ÌµÄÊý¾Ý¿â£¬²¢Í¨¹ýÍòÎÞһʧµÄÊý¾Ý´«Êä»úÖÆÀ´Ö ......

»ñÈ¡SQL ServerµÄµ±Ç°Á¬½ÓÊý

»ñÈ¡SQL ServerµÄµ±Ç°Á¬½ÓÊý
[ת]http://www.cnblogs.com/confach/archive/2006/05/31/414156.html
Ê×ÏÈÉùÃ÷:Õâ¸öÎÊÌâÎÒûÓнâ¾ö
µ±ÍøÓÑÎʵ½ÎÒÕâ¸öÎÊÌâʱ,ÎÒÒ²»¹ÒÔΪºÜ¼òµ¥,ÒÔΪSQL ServerÓ¦¸ÃÌṩÁ˶ÔÓ¦µÄϵͳ±äÁ¿Ê²Ã´µÄ.µ«Êǵ½Ä¿Ç°ÎªÖ¹,ÎÒ»¹Ã»Óеõ½Ò»¸ö±È½ÏºÃµÄ½â¾ö·½°¸.¿ÉÄܼܺòµ¥,,Ö»²»¹ýÎÒ²»ÖªµÀ°ÕÁË.Ï£ÍûÈç´Ë.. ......

ÐÞ¸Äsql server µÄÁ¬½ÓÊý

 ÈçºÎÐÞ¸ÄSQL ServerµÄÁ¬½ÓÊý
ÎÒ°ÑSQL   Server   7.0µÄÓû§Á¬½ÓÊýÉèΪ1ºó£¬Êý¾Ý¿â¾ÍÔÙÒ²Á¬²»ÉÏÁË£¬ËùÒÔҲû°ì·¨ÐÞ¸ÄÁ¬½ÓÊý  
  ÇëÎÊÓÐʲô°ì·¨ÄÜÐÞ¸ÄÁ¬½ÓÊý£¿
ÔÚserver   µÄÊôÐÔÀïÃæÓиöconnetctions     µÄ  
   
  maximun     concurr ......

SQLÓïÑÔ»ù±¾ÓïÑÔ

SQL·ÖÀࣺ
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database db ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ