-- create by zh
-- n ÊÇ×÷ÎïµÄʱ¼ä,x ÊÇÏ£ÍûÔÚ¼¸µã³ÉÊì,·µ»Ø²¥ÖÖµÄʱ¼ä
with t as
(
select 64 n,9 x from dual union all
select 64 n,13 x from dual union all
select 64 n,17 x from dual union all
select 64 n,20 x from dual
)
select '³ÉÊìʱ¼ä:' || lpad(to_char(n),4,' ') || ' ;' ||
'ժȡʱ¼ä:' || lpad(to_char(x),4,' ') || ' ;' ||
'²¥ÖÖʱ¼ä:' || lpad(to_char(mod(24+( x - mod( n,24)),24)),4,' ') || ' ;'
jg from t
......
-- create by zh
-- n ÊÇ×÷ÎïµÄʱ¼ä,x ÊÇÏ£ÍûÔÚ¼¸µã³ÉÊì,·µ»Ø²¥ÖÖµÄʱ¼ä
with t as
(
select 64 n,9 x from dual union all
select 64 n,13 x from dual union all
select 64 n,17 x from dual union all
select 64 n,20 x from dual
)
select '³ÉÊìʱ¼ä:' || lpad(to_char(n),4,' ') || ' ;' ||
'ժȡʱ¼ä:' || lpad(to_char(x),4,' ') || ' ;' ||
'²¥ÖÖʱ¼ä:' || lpad(to_char(mod(24+( x - mod( n,24)),24)),4,' ') || ' ;'
jg from t
......
1 ·ÀÖ¹sql×¢Èëʽ¹¥»÷(¿ÉÓÃÓÚUI²ã¿ØÖÆ£© #region ·ÀÖ¹sql×¢Èëʽ¹¥»÷(¿ÉÓÃÓÚUI²ã¿ØÖÆ£©
2
3 /**/ ///
4 /// ÅжÏ×Ö·û´®ÖÐÊÇ·ñÓÐSQL¹¥»÷´úÂë
5 ///
6 /// ´«ÈëÓû§Ìá½»Êý¾Ý
7 /// true-°²È«£»false-ÓÐ×¢Èë¹¥»÷ÏÖÓУ»
8 public bool ProcessSqlStr( string inputString)
9 {
10 string SqlStr = @" and|or|exec|execute|insert|select|delete|update|alter|create|drop|count|\*|chr|char|asc|mid|substring|master|truncate|declare|xp_cmdshell|restore|backup|net +user|net +localgroup +administrators " ;
11 try
12 {
13 if ((inputString != null ) && (inpu ......
1 ·ÀÖ¹sql×¢Èëʽ¹¥»÷(¿ÉÓÃÓÚUI²ã¿ØÖÆ£© #region ·ÀÖ¹sql×¢Èëʽ¹¥»÷(¿ÉÓÃÓÚUI²ã¿ØÖÆ£©
2
3 /**/ ///
4 /// ÅжÏ×Ö·û´®ÖÐÊÇ·ñÓÐSQL¹¥»÷´úÂë
5 ///
6 /// ´«ÈëÓû§Ìá½»Êý¾Ý
7 /// true-°²È«£»false-ÓÐ×¢Èë¹¥»÷ÏÖÓУ»
8 public bool ProcessSqlStr( string inputString)
9 {
10 string SqlStr = @" and|or|exec|execute|insert|select|delete|update|alter|create|drop|count|\*|chr|char|asc|mid|substring|master|truncate|declare|xp_cmdshell|restore|backup|net +user|net +localgroup +administrators " ;
11 try
12 {
13 if ((inputString != null ) && (inpu ......
ÔÚÎÒÃÇÈÕ³£Ê¹ÓÃSQL ServerÊý¾Ý¿âʱ£¬¾³£Óöµ½ÐèÒªÔÚʵÀýInstance01ÖпçʵÀý·ÃÎÊInstance02ÖеÄÊý¾Ý¡£ÀýÈçÔÚ×öÊý¾ÝÇ¨ÒÆÊ±£¬ÈçÏÂÓï¾ä:
insert into Instance01.DB01.dbo.Table01
select * from Instance02.DB01.dbo.Table01
ÆÕͨÇé¿öÏ£¬ÕâÑù×öÊDz»ÔÊÐíµÄ£¬ÒòΪSQL ServerĬÈϲ»¿ÉÒÔ¿çʵÀý·ÃÎÊÊý¾Ý¡£½â¾ö·½°¸ÊÇʹÓô洢¹ý³Ìsp_addlinkedserver½øÐÐʵÀý×¢²á¡£
sp_addlinkedserverÔÚMSDNÖе͍ÒåΪ:
sp_addlinkedserver [ @server= ] 'server' [ , [ @srvproduct= ] 'product_name' ]
[ , [ @provider= ] 'provider_name' ]
[ , [ @datasrc= ] 'data_source' ]
[ , [ @location= ] 'location' ]
[ , [ @provstr= ] 'provider_string' ]
[ , [ @catalog= ] 'catalog' ]
ÀýÈ磺ÔÚInstance01ʵÀýÖУ¬Ö´ÐÐÈçÏÂSQLÓï¾ä
EXEC sp_addlinkedserver ‘Instance02’ //Ö ......
»ùÓÚmsdn ÏêϸѧϰT-SQL (http://msdn.microsoft.com/zh-cn/library/bb510741.aspx)
Aggregate function--Sum() Two Sample from msdn
USE AdventureWorks;
GO
SELECT Color, SUM(ListPrice), SUM(StandardCost)
from Production.Product
WHERE Color IS NOT NULL
AND ListPrice != 0.00
AND Name LIKE 'Mountain%'
GROUP BY Color
ORDER BY Color;
GO
USE AdventureWorks;
GO
SELECT Color, ListPrice, StandardCost
from Production.Product
WHERE Color IS NOT NULL
AND ListPrice != 0.00
AND Name LIKE 'Mountain%'
ORDER BY Color
COMPUTE SUM(ListPrice), SUM(StandardCost) BY Color;
GO
......
ÎÊÌâÒ»
ÓÐÕâÑùµÄÒ»¸öÎÊÌ⣬Êý¾Ý¿âÖÐÓÐÁ½¸ö±í£¬·Ö±ðÊÇGuest,Hotel£¬¼´ÂÿÍÐÅÏ¢±íºÍÂùÝÐÅÏ¢±í£¬Guest±íÖÐÓÐÒ»¸öÂÿͱàÂëµÄ×ֶΣ¬Õâ¸ö×ֶεÄÓÐ20룬ËüµÄǰ10λ´ú±íÕâ¸öÂÿÍËùסµÄÂùݣ¬ÏÖÔÚµÄÎÊÌâÊÇÒª¸ù¾ÝGuest±íÖеÄÂÿͱàÂë×Ö¶ÎÐÅÏ¢²éµ½ËûËùסµÄÂùݵÄÃû³ÆºÍÂùݵØÖ·£¡
ÎÊÌâ½â¾ö:
SQL SERVERµÄSQLÓï¾ä£ºselect Guest.ÂÿͱàÂë,Guest.ÂÿÍÐÕÃû,Hotel.ÂùÝÃû³Æ,Hotel.ÂùݵØÖ· from Guest,Hotel where Hotel.ÂùݱàÂë=SubString(Guest.ÂÿͱàÂë,1,10)
OracleµÄSQLÓï¾ä£ºselect Guest.ÂÿͱàÂë,Guest.ÂÿÍÐÕÃû,Hotel.ÂùÝÃû³Æ,Hotel.ÂùݵØÖ· from Guest,Hotel where Hotel.ÂùݱàÂë=SubStr(Guest.ÂÿͱàÂë,1,10)
  ......
Five basic search conditions are summarized here:
1) Comparison test
2) Range test
3) Set membership test
4) Pattern matching test (Like)
The pattern matching test checks to see whether the data value in a column matches a specified pattern
% mathes any sequence of zero or more characters.
_ matches any single character.
// Find products whose product IDs start with the four letters "A%BC"
SELECT order_num ,product
from orders
WHERE product LIKE 'A$%BC' ESCAPE '$' ;
5) Null value test (IS NULL)
In SQL's three-valued logic, a search condition can yield a TRUE,FALSE, or NULL result. Only rows where search codition yields a TRUE result are included in the query result.
Rules For Single-Table Query Processing
The from clause is applied first; the where clause is applied next ; the SELECT clause is applied next . Finally ......