SQLÖÐÒÔÈÕÆÚΪÌõ¼þͳ¼Æ·½·¨
/*ͳ¼ÆÿÌìÊý¾Ý×ÜÁ¿ÈýÖÖ·½·¨£º
select convert(char(10),happentime ,120) as date ,count(1) from table1
group by convert(char(10),happentime ,120) order by date desc
select day(happentime) as date,count(*) from table1
group by day(happentime) order by date desc
SELECT left([happentime],5),count (1)
from [database].[dbo].[ table1]
group by left([happentime],5)
order by left([happentime],5)
˵Ã÷£ºhappentimeΪ±í×Ö¶ÎÃû;
´ó¼Ò·Ö±ð²âÊÔÏ left([happentime],20) Óë convert(char(10),happentime ,120) ¡¢day(happentime) Á½ÕßµÄÇø±ð£¬¶ÔÓÚÐÂÈËÀ´Ëµ£¬´Óleft([happentime],5) À´¿´½á¹ûÍùÍù¿´²»³öÀ´ÓëÆäËûÁ½¸öµÄ²»Í¬¡£
Èç¹û²»Ã÷°×Óï¾äÈçºÎд£¬Çë²Î¿¼ÈçÏÂ:
select convert(char(10),happentime ,120) from table1
SELECT left([happentime],5) from table1
SELECT left([happentime],5) from table1
Ïà¹ØÎĵµ£º
ÔÚSQLÖÐSelectÓï¾äµÄÖ´ÐÐ˳ÐòÈçÏ£º
(1)from×Ӿ䣬×é×°À´×Ô²»Í¬Êý¾ÝÔ´µÄÊý¾Ý
(2)WHERE×Ӿ䣬¸øÓèÖ¸¶¨Ìõ¼þ¶Ô¼Ç¼½øÐÐɸѡ
(3)GROUP BY×Ӿ䣬½«Êý¾Ý»®·ÖΪ¶à¸ö×é
(4)ʹÓþۼ¯º¯Êý½øÐмÆËã
(5)ʹÓÃHAVING×Ó¾äɸѡ·Ö×é
(6)¼ÆËãËùÓбí´ïʽ
(7)ʹÓÃORDER BY¶Ô½á¹û½øÐÐÅÅÐò ......
--@@CPU_BUSY»ñÈ¡cpu¹¤×÷ʱ¼ä
select @@CPU_BUSY AS 'CPU ms',GETDATE() AS 'TIMES'
--»ñÈ¡´ÅÅ̶Áд´ÎÊý
SELECT @@TOTAL_READ AS 'Reads',@@TOTAL_WRITE AS 'Writes', GETDATE() AS 'As of'
--»ñÈ¡SQl·þÎñÆ÷Ãû
SELECT HOST_NAME()
--»ñµÃÊý¾Ý¿â±íʾºÅ
USE master
SELECT name,DB_ID(name) AS DB_ID from sysd ......
1 :ÆÕͨSQLÓï¾ä¿ÉÒÔÓÃExecÖ´ÐÐ
Àý: Select * from tableName
Exec('select * from tableName')
& ......
ÈçºÎÈÃÄãµÄSQLÔËÐеøü¿ì
---- ÈËÃÇÔÚʹÓÃSQLʱÍùÍù»áÏÝÈëÒ»¸öÎóÇø£¬¼´Ì«¹Ø×¢ÓÚËùµÃµÄ½á¹ûÊÇ·ñÕýÈ·£¬¶øºöÂÔ
Á˲»Í¬µÄʵÏÖ·½·¨Ö®¼ä¿ÉÄÜ´æÔÚµÄÐÔÄܲîÒ죬ÕâÖÖÐÔÄܲîÒìÔÚ´óÐ͵ĻòÊǸ´ÔÓµÄÊý¾Ý¿â
»·¾³ÖУ¨ÈçÁª»úÊ ......
sql server2000ÖÐʹÓÃconvertÀ´È¡µÃdatetimeÊý¾ÝÀàÐÍÑùʽ£¨È«£©
ÈÕÆÚÊý¾Ý¸ñʽµÄ´¦Àí£¬Á½¸öʾÀý£º
CONVERT(varchar(16), ʱ¼äÒ», 20) ½á¹û£º2007-02-01 08:02/*ʱ¼äÒ»°ãΪgetdate()º¯Êý»òÊý¾Ý±íÀïµÄ×Ö¶Î*/
CONVERT(varchar(10), ʱ¼äÒ», 23) ½á¹û£º2007-02-01 /*varchar(10)±íʾÈÕÆÚÊä³öµÄ¸ñʽ£¬Èç¹û²»¹»³¤»á·¢Éú½ØÈ¡*/ ......