100·ÖÇó¸öSQLµÄÓï·¨¡£¡£ - Oracle / ¿ª·¢
ÏÖÔÚ Óиö ±í ×Ö¶ÎΪ A1,A2,A3,A4,A5
ÎÒ¶¨ÒåÁ˼¸¸ö±äÁ¿ ÀýÈ磺
v_B1 NUMBER;
v_B2 NUMBER;
v_B3 NUMBER;
ÎÒÒª²é³öÒ»¸ö½á¹û¼¯£»
Õâ¸ö½á¹û¼¯ºÏÒªÇó£º
select SUM(A1)/COUNT(DISTINCT A2) into v_B1 from t_daylog_agentoprinfo;
select SUM(A3)/SUM(A4) into v_B2 from t_daylog_agentoprinfo where a5='2222'
select SUM(A3) into v_B3 from t_daylog_agentoprinfo WHERE a5='234';
Õâ3¸ö±äÁ¿·Ö±ðͨ¹ýÕâ¸ö±íµÄ²»Í¬¼ÆË㷽ʽ¸³Öµ£¡£¡£¡£¡ ÈçºÎ½«Õâ3¸ö±äÁ¿ Æ´½ÓÆðÀ´ ²¢ÇÒ²éѯ³öÒ»¸ö½á¹û¼¯ºÏ¡£¡£ÕâÑùµÄÓï·¨Ôõôд£¿£¿£¿£¿£¿£¿
Çë¸÷λ°ïÏ¡£
²»Ì«Ã÷°×˵µÄʲôÒâ˼
»¹ÓÐÆäËû·½·¨Ã»¡£¡£²»Ð´³ÉÒ»¸öÓï¾ä¡£¡£¡£
ÒòΪ¼ÆËã±È½Ï¸´ÔÓ¡£¡£ÕâÀïÊǾٸöÀý×Ó ¡£¡£ËùÒÔÏȼÆËã±£´æµ½±äÁ¿ ÔÚ ²éѯ½á¹û¼¯ºÏ£¨ÕâÑùÓï·¨Ôõôд£©¡£¡£Â¥É쵀 ÊÇÖ±½Óд£¬ÎÒÏëÕâÑù²»Ì«ºÃ°É¡£¡£¡£
v_sSQL := ' SELECT ''' || v_TmpStr||'''|| TO_CHAR(SYSDATE,''YYMMDDHH24MISS'') || '''|| v_Othid ||''' FILENAME, '
|| ''''||v_TmpStr || ''' ShortName, '
|| ''''||TO_CHAR(v_BeginDate,'YYYYMMDDHH24MISS') ||''' BeginDate, '
|| ''''||TO_CHAR(v_EndDate,'YYYYMMDDHH24MISS') ||''' EndDate, '
|| ' ''000'' UserType, ''000'' SubUserType, '
|| ' a.NetType, '
|| ' a.InCallNum '
|| ' from ICD.t_H1V7_CallBy10011CG a, ICDMAIN.t_H1_Cit
Ïà¹ØÎÊ´ð£º
ÏÖÔÚÓÐÁ½ÕÅ±í£ºÎÄÕÂÖ÷±íA(articleId,articleTitle)£¬ÎÄÕÂÆÀÂÛ±íB(commentId,articleId,commentTitle)
ÏÖÔÚÎÒÏëʵÏÖÕâÑùµÄ¹¦ÄÜ£ºÁгöÎÄÕÂÁÐ±í£¬ÆäÖÐÿƪÎÄÕ±êÌâÏÂÃæÁгö´ËÎÄÕµÄÇ°2¸öÎÄÕÂÆÀÂÛ£¬ÇëÎÊsqlÓï¾äÔõôд°¡ ......
ÕâÀïÏëÁ˽âÏ£¬¹ØÓÚSQL ServerÖзÖÒ³ºÍOracleÖзÖÒ³£»
ƽ³£Ð´Ó¦ÓóÌÐòµÄʱºò£¬±ÈÈçÓõÄÓïÑÔÊÇJava£¬ÓиöÁбíÒ³Ã棬ÐèÒª¶ÔÊý¾Ý·ÖÒ³ÏÔʾ£»
ÕâÀïÒª·ÖÒ³ÄѵÀ²»ÐèÒª½èÖúJava£¬¶øÖ±½ÓsqlÄÜÖªµÀ·ÖÒ³Âð£¬ÆðÂëÒ²Òª´«¸öÒ³Âë½ ......
SQL code:
CREATE OR REPLACE PROCEDURE usp_refreshTopN IS
BEGIN
--Îĵµ
INSERT INTO topnresource(resourceId,title,type,cover,brief,properUser,tag,clickAmount,createDate,topNCreateDate,organizat ......
±íÊý¾Ý
COL1 COL2 COL2 COL4 COL5
----------------------------------------------------------------------------------------------
2010-05-05 00:00 ......
ͨ¹ýNAME×Ö¶ÎÌõ¼þ²éѯһ¸öÊý¾Ý±í£¬¼ÙÉèÎÒÓÐ100¸öÐÕÃû£¬ÓÐÒÔÏÂÁ½¸ö·½·¨£¬
·½·¨1£º
°Ñ100¸öName ×é³ÉÒ»¸öSQLÓï¾ä£¬±ÈÈç Select * from tmp_table where Name='ÕÅÈý' or Name ='ÀîËÄ' Or ...Or Name='µÚÒ»°Ù¸öÐÕÃû'
......