SQL SERVERÖÐROLLUP ÔËËã·ûµÄÓ÷¨
ÎÊÌâµÄÌá³ö£º
ÏÖÓбíA£¬ÄÚÈÝÈçÏ£º
±àÂë ²Ö¿â ÊýÁ¿
01 A 6
01 B 7
02 A 8
02 B 9
ÏÖÔÚÏë°´±àÂë²éѯ³öÕâÖÖ¸ñʽ:
--------------------
01 A 6
01 B 7
»ã×ÜС¼Æ£º 13
02 A 8
02 B 9
»ã×ÜС¼Æ£º 17
ÎÊ£º¸ÃÈçºÎʵÏÖ£¿
Õ§Ò»¿´£¬ºÃÏñºÜÈÝÒ×£¬ÓÃgroup byºÃÏñÄÜʵÏÖ£¿µ«×ÐϸÑо¿ÏÂÈ¥£¬ÄãÓÖ»á¾õµÃgroup byÒ²ÊÇÎÞÄÜΪÁ¦£¬×ÜǷȱµãʲô£¬ÎÞ´ÓÏÂÊÖ¡£ÄÇô£¬µ½µ×¸ÃÈçºÎ×öÄØ£¿±ð¼±£¬SQL ServerÔç¾Í°ïÎÒÃÇ×öºÃÁË£¬ÏÂÃ棬¸úÎÒÀ´¡£
Ê×ÏÈ£¬ÈÃÎÒÃÇÀ´¿´Ò»¶Î»°£º
ÔÚÉú³É°üº¬Ð¡¼ÆºÍºÏ¼ÆµÄ±¨±íʱ£¬ROLLUP ÔËËã·ûºÜÓÐÓá£ROLLUP ÔËËã·ûÉú³ÉµÄ½á¹û¼¯ÀàËÆÓÚ CUBE ÔËËã·ûËùÉú³ÉµÄ½á¹û¼¯¡£
£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
CUBE ÔËËã·ûÉú³ÉµÄ½á¹û¼¯ÊǶàάÊý¾Ý¼¯¡£¶àάÊý¾Ý¼¯ÊÇÊÂʵÊý¾ÝµÄÀ©Õ¹£¬ÊÂʵÊý¾Ý¼´¼Ç¼¸ö±ðʼþµÄÊý¾Ý¡£À©Õ¹½¨Á¢ÔÚÓû§´òËã·ÖÎöµÄÁÐÉÏ¡£ÕâЩÁб»³ÆΪά¡£¶àάÊý¾Ý¼¯ÊÇÒ»¸ö½á¹û¼¯£¬ÆäÖаüº¬Á˸÷ά¶ÈµÄËùÓпÉÄÜ×éºÏµÄ½»²æ±í¸ñ¡£
CUBE ÔËËã·ûÔÚ SELECT Óï¾äµÄ GROUP BY ×Ó¾äÖÐÖ¸¶¨¡£¸ÃÓï¾äµÄÑ¡ÔñÁбíÓ¦°üº¬Î¬¶ÈÁк;ۺϺ¯Êý±í´ïʽ¡£GROUP BY Ó¦Ö¸¶¨Î¬¶ÈÁк͹ؼü×Ö WITH CUBE¡£½á¹û¼¯½«°üº¬Î¬¶ÈÁÐÖи÷ÖµµÄËùÓпÉÄÜ×éºÏ£¬ÒÔ¼°ÓëÕâЩά¶ÈÖµ×éºÏÏàÆ¥ÅäµÄ»ù´¡ÐÐÖеľۺÏÖµ¡£
£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½£½
CUBE ºÍ ROLLUP Ö®¼äµÄÇø±ðÔÚÓÚ£º
CUBE Éú³ÉµÄ½á¹û¼¯ÏÔʾÁËËùÑ¡ÁÐÖÐÖµµÄËùÓÐ×éºÏµÄ¾ÛºÏ¡£
ROLLUP Éú³ÉµÄ½á¹û¼¯ÏÔʾÁËËùÑ¡ÁÐÖÐÖµµÄijһ²ã´Î½á¹¹µÄ¾ÛºÏ¡£
&n
Ïà¹ØÎĵµ£º
¸ñʽ:
CONVERT(data_type,expression[,style])
˵Ã÷:
´ËÑùʽһ°ãÔÚʱ¼äÀàÐÍ(datetime,smalldatetime)Óë×Ö·û´®ÀàÐÍ(nchar,nvarchar,char,varchar)
Ï໥ת»»µÄʱºò²ÅÓõ½.
Àý×Ó:
SELECT CONVERT(varchar(30),getdate(),101) now
½á¹ûΪ:
now
---------------------------------------
|09/15/2001
===== ......
1¡¢°´Ê±¼äÅÅÐò
select * from tbl_lms_loginhistory order by loginhistory_logintime desc
2¡¢
ÔÚÒ»¸öÊý¾Ý¿âÖÐÊÇÏÂÁеÄÑù×Ó
³µ´Î Éí·ÝÖ¤ºÅ
27 1
27 2
45 1
25 1
45 2
ÏÖÔÚÎÒÏë »ñµÃµÄÊÇ
³µ´Î ³Ë×ø´ÎÊý
25 1
27 3
45 2
ÇëÎÊ£¬ÎÒµÄSQLÓï¾ä¸ÃÔõôд£¿
select ³µ´ ......
Ò»¡¢PL/SQL±à³Ì¹æ·¶Ö®´óСд
¾ÍÏñÔÚSQLÖÐÒ»Ñù£¬PL / SQLÖÐÊDz»Çø·Ö´óСдµÄ¡£ÆäÒ»°ã×¼ÔòÈçÏ£º
¹Ø¼ü×Ö(BEGIN, EXCEPTION, END, IF THEN ELSE,LOOP, END LOOP)¡¢Êý¾ÝÀàÐÍ(VARCHAR2, NUMBER)¡¢ÄÚ²¿º¯Êý(LEAST, SUBSTR)ºÍÓû§¶¨ÒåµÄ×Ó³ÌÐò(procedures, functions,packages)£¬Ê¹Óôóд¡£
±äÁ¿ÃûÒÔ¼°SQLÖеÄÁÐÃûºÍ±íÃû£¬Ê¹ÓÃÐ ......
ORACLEÖÐ×ֶεÄÊý¾ÝÀàÐÍ
×Ö·ûÐÍ char ·¶Î§ ×î´ó2000¸ö×Ö½Ú ¶¨³¤
char(10) 'ÕÅÈý' ºóÌí¿Õ¸ñ6¸ö°Ñ10¸ö×Ö½Ú²¹Âú 'ÕÅÈý &nb ......
SQLÓï¾äʵÏÖ£¬SQL Server 2000 ¼°ACCESS¸´ÖƾɱíOldTableµÄ½á¹¹£¬»ò½á¹¹¼°ÄÚÈݵ½ÐµıíNewTable
Á½¸ö¶¼ÊÔ¹ýÁË£¬ÏÂÃæµÄ´úÂëÔÚÕâÁ½¸öÊý¾Ý¿âÖУ¨SQL Server 2000 ¼°ACCESS£©¶¼ÊÇ¿ÉÒÔͨ¹ýµÄ¡£
--¸´ÖƱí½á¹¹ÎªÐµıí
select * into NewTable
from OldTable where 1=2
--¸´ÖƱí½á¹¹¼°ÄÚÈݵ½Ðµıí
select * into newtable
......