Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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²éѯËٶȻºÂý½â¾ö°ì·¨(1)

SQL ServerÊý¾Ý¿â²éѯËÙ¶ÈÂýµÄÔ­ÒòÓкܶ࣬³£¼ûµÄÓÐÒÔϼ¸ÖÖ£º
1¡¢Ã»ÓÐË÷Òý»òÕßûÓÐÓõ½Ë÷Òý(ÕâÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣬ÊdzÌÐòÉè¼ÆµÄȱÏÝ)
2¡¢I/OÍÌÍÂÁ¿Ð¡£¬ÐγÉÁËÆ¿¾±Ð§Ó¦¡£
3¡¢Ã»Óд´½¨¼ÆËãÁе¼Ö²éѯ²»ÓÅ»¯¡£
4¡¢ÄÚ´æ²»×ã
5¡¢ÍøÂçËÙ¶ÈÂý
6¡¢²éѯ³öµÄÊý¾ÝÁ¿¹ý´ó(¿ÉÒÔ²ÉÓöà´Î²éѯ£¬ÆäËûµÄ·½·¨½µµÍÊý¾ÝÁ¿)
7¡¢Ëø»òÕß ......

SQL Server 2008 °¸Àý֮΢ÈíIT²¿ÃÅ

“¾­¹ý²âÊÔÎÒÃÇ·¢ÏÖSQL Server 2008µ±Öеı¸·ÝѹËõ¹¦ÄÜ¿ÉÒÔ1-3±¶µÄѹËõ±È£¬´Ó¶ø¼«´óµÄ¼õÉÙ±¸·ÝËùÐèµÄ´ÅÅ̿ռ䡣”Alexey Yeltsov, ΢Èíϵͳ¹ÜÀíÔ±Ö÷¹Ü¡£
΢ÈíÔÚÈ«ÊÀ½ç¹²ÓÐ6Íò¶àÃûÔ±¹¤£¬ÔÚ2006ÄêµÄ²ÆÕþÊÕÈ볬¹ýÁË500ÒÚÃÀ½ð£¬Óë´ËͬʱҲ²úÉúÁË´óÁ¿ÄÚ²¿Êý¾Ý£¬¹«Ë¾Ï£Íû¶ÔÕâЩÊý¾Ý½øÐм¯ÖÐÒÔ±ãÌṩ¿Í»§µÄ¼¯³É»¯ÊÓͼ¡£ ......

SQL SERVER»ñÈ¡±íµÄ¿Õ¼ä·Ö²¼Çé¿ö

/********************************
¹¦ÄÜ£º»ñÈ¡±íµÄ¿Õ¼ä·Ö²¼Çé¿ö
**********************************/
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tablespaceinfo]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
create table  tablespaceinfo      ......

sqlÓï¾ä»ù±¾²Ù×÷

1.½¨±íÓï¾ä£ºcreate table
Ó÷¨: create table ±íµÄÃû×Ö (×Ö¶Î1, ×Ö¶Î2,¡£¡£¡£¡£)
¾ÙÀý£ºÀýÈç´´½¨Ò»¸öѧÉú³É¼¨±í£¬°üº¬µÄ×Ö¶ÎÓУ¬Ñ§Éúid£¬ÐÕÃû£¬ÐԱ𣬰༶£¬³É¼¨create table score(
create table score(
 sid nvarchar(10) primary key,
 sname nvarchar(10) not null,
 sex nvarchar(2),
 sc ......

SQLÓïÑԵIJ¼¾ÖºÍIllegalArgumentException

ºÍjava.lang.IllegalArgumentException: org.hibernate.QueryException: JPA-style positional param was not an integral ordinalÕ½¶·ÁË°ëÌ죬º¹°¡£¡
ʹÓÃjpa + strut+ hibernate ¾Í±¨org.hibernate.QueryException: JPA-style positional param was not an integral ordinal
Ò»°ã°ÑhqlÓï¾äдÔÚÒ»ÐУ¬»áºÜ³¤£¬ÔÚideÖÐÐèÒ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ