SqlserverÖÐCompute By×Ó¾äÓ÷¨·ÖÎö
SqlserverÖÐCompute By×Ó¾äÓ÷¨·ÖÎö
2007Äê04ÔÂ20ÈÕ ÐÇÆÚÎå 08:05
ʹÓÃCompute by×Ó¾äºÍÐÐͳ¼Æº¯Êý£¨count,sum,max,avg,minµÈ£©£¬¿ÉÒÔͳ¼ÆÅÅÐòÖнá¹ûÍêÈ«ÏàͬµÄÁУ¬Í³¼ÆÖµ×÷Ϊ²éѯ½á¹ûÒÔ¸½¼ÓÐеÄÐÎʽÏÔʾ£¬
Óï·¨£ºCompute avg|count|max|min|sum by ±í´ïʽ
1¡¢¾ÙÒ»¸öÀý×Ó
±ÈÈçÓÐÒ»¸öÊý¾Ý±í£º±íÃûΪperson,Èý¸ö×ֶηֱðΪ name,age,country
select name,country,age from person where ?? order by a compute sum(age),max(age),min(age) by country
Õâ¸öÓï¾äÔÚ²éѯʱ½«Êý¾Ý°´ÕÕcountry·Ö×飬Ȼºó·Ö±ðÏÔʾÿ×éµÄÏêϸÐÅÏ¢ºÍͳ¼ÆÐÅÏ¢¡£½á¹û¿ÉÄÜÈçÏ£º
name country age
ÕÅÈý Öйú 16
ÀîËÄ Öйú 21
ÍõÎå Öйú 24
sum max min
61 24 16
=================================
name country &nb
Ïà¹ØÎĵµ£º
1.oracle»·¾³
create table test
(
id number(4),
name varchar2(20)
)
ÔÚÒ»¸ösessionÖÐ
insert into test values(1,'aa');
ÔÚÁíÒ»¸ösessionÖÐ
select * from test1;
²éѯû±»×èÈû
2.sqlserver»·¾³
ÔÚÒ»¸ösessionÖÐ
insert into test values(1,'aa');
ÔÚÁíÒ»¸ösessionÖÐ
select * from test1;
²éѯ±»×èÈû(Ê ......
½ñÌìÔÚÍøÉÏÕÒÁËÐí¾Ã¹ØÓÚsqlserverÖд洢imageÀàÐͺͶÁÈ¡imageµÄ·½·¨£¬¿ÉÊǶ¼ÊÇÄÇôһµã£¬¹ÊÔÚ´ËÂÞÁÐһϣ¬Ï£Íû¿ÉÒÔ°ïÖú´ó¼Ò¡£
Ê×ÏÈÊǹØÓÚdataGridViewµÄ°ó¶¨¡£´úÂë¼ûÏÂ
private void button_show_Click(object sender, EventArgs e)
{
string sqlText = "server=localhost;initial catalog=Test; ......
Ê×ÏȲå¾äÌâÍâ»°£º´´½¨Ò»¸ö×ÔÈ»Êý±íNums¡£ÕâÊÇ¡¶SQL Server 2005¼¼ÊõÄÚÄ»£ºT-SQL²éѯ¡·Ò»ÊéµÄ½¨Òé¡£
ÔÚSQL Server 2005ÖУ¬¿ÉÒÔ½èÓÃROW_NUMBERÅÅÃûº¯ÊýÇáËÉÉú³ÉÎÒÃÇËùÐèµÄ×ÔÈ»Êý±í£º
--×ÔÈ»Êý±í1-1M
CREATE TABLE Nums(n int NOT NULL PRIMARY KEY CLUSTERED)
WITH B1 AS(SELECT n=1 UNION ALL SELECT n=1), --2
B2 AS( ......
eg:
select * from Exception_Log where DATEDIFF(day,OPER_DATE,getdate())<30 ;
/*
oper_date Ϊ±íÖвéѯ³öÀ´µÄʱ¼ä
getdate()ΪSQLServerÀïÃæ»ñµÃϵͳʱ¼äµÄº¯Êý
º¬Ò壺µ±Ç°Ê±¼ä-²éѯ³öÀ´µÄʱ¼äСÓÚ30Ìì
DateDiff¾ßÌåÓ÷¨£º
*/
DateDiff º¯Êý
·µ»ØÁ½¸öÈÕÆÚÖ®¼äµÄʱ¼ä¼ä¸ô¡£
DateDiff(interval, date1, da ......
ÓÐЩ³£¼ûµÄÎÊÌâÔÚÂÛ̳Öв»¶Ï³öÏÖ£¬²»·ÁÕûÀíһϡ£
ÒÔÏÂÓï¾äÊÇÔÚSQLServer2005ÉÏʵÏֵģ¬Ò»Ð©Óï¾äÎÞ·¨ÔÚSS2000ÉÏÖ´ÐС£
ÓÐÓÃÖ¸ÊýÊÇÎÒ¸ù¾ÝÕâ¸öÎÊÌâµÄ³£¼û³Ì¶È´òµÄ·Ö£¬½ö¹©²Î¿¼¡£Êµ¼ÊÉÏ£¬µ±ÄãÓöµ½ÁËÕâ¸öÎÊÌ⣬Õâ¸öÎÊÌâÄÄÅÂÔÙÉÙ¼û£¬½â¾ö·½°¸Ò²ÊǷdz£ÓÐÓõġ£
1. Éú³ÉÈô¸ÉÐмǼ
ÓÐÓÃÖ¸Êý£º¡ï¡ï¡ï¡ï¡ï
³£¼ûµÄÎÊÌâÀàÐÍ£º¸ù¾Ý ......