SQLÈ¥³ýijһ×Ö¶ÎÖµÖظ´¼Ç¼µÄ·½·¨
ÔÀí£º¶ÔÐèҪȥÖظ´¼Ç¼µÄ×ֶΰ´×éÅÅÐò£¬È»ºóÈ¡ÆäÖÐÒ»Ìõ¼Ç¼¡£ÔÚ×ܲéѯÓï¾äÖÐʹÓÃinÓï·¨¹ýÂË
È¥µôÖظ´¼Ç¼
select * from company where comid in (select Max(comid) from company group by companyname)
µÃµ½Öظ´¼Ç¼Êý
select * from company where comid not in (select Max(comid) from company group by companyname)
¶ÔÍêÈ«ÏàͬµÄ¼Ç¼¿ÉÒÔʹÓÃDISTINCT ¶Ô¼Ç¼½øÐÐΨһÐÔ¹ýÂË
Ïà¹ØÎĵµ£º
Subquery: (single-row subqueries and multi-rows subqueries).
select select_list
from table
where expr operator (select select_list from table);
single-row subqueries operator: =, >, >=, <, <=, <>
e.g.:
1. select department_id, min(salary) from employees group by department_id ......
constraint Example:
1. grammer:
create table [schema.]table
(column datatype [DEFAULT expr]
[column_constraint], ...
[table_constraint] [,......]);
2. example of a column_level constraint:
create table empl ......
GRANT
Name
GRANT -- ¶¨Òå·ÃÎÊȨÏÞ
Synopsis GRANT { { SELECT | INSERT | UPDATE | DELETE | RULE | REFERENCES | TRIGGER }
[,...] | ALL [ PRIVILEGES ] }
ON [ TABLE ] tablename [, ...]
TO { username | GROUP groupname | PUBLIC } [, ...] [ WI ......
Merge statement
function benefits: 1) provides the ability to conditionally update, insert or delete data into a database table. 2) performs an update if the row exists, and an insert if it is a new row. --> 1) avoids seperate updates, 2) increase performance and ease of use. 3) is useful in dat ......
ͨÅä·û_
"_"ºÅ±íʾÈÎÒâµ¥¸ö×Ö·û,¸Ã·ûºÅÖ»ÄÜÆ¥ÅäÒ»¸ö×Ö·û."_"¿ÉÒÔ·ÅÔÚ²éѯÌõ¼þµÄÈÎÒâλÖÃ,ÇÒÖ»ÄÜ´ú±íÒ»¸ö×Ö·û.Ò»¸öºº×ÖֻʹÓÃÒ»¸ö"_"±íʾ.
Àý×Ó£º
if PATINDEX('%[ß¹-×ö]%','ÐèÒªÅжϵÄ×Ö·û')>0 -- ÅжÏÊÇ·ñÓÐ×Ö·û
print 'Óкº×Ö'
else
print 'ÎÞºº×Ö'
ͨÅä·û%
"%"·ûºÅÊÇ×Ö·ûÆ¥Åä·û,ÄÜÆ¥Åä0¸ö»ò¸ü¶à×Ö·ûµÄÈÎÒⳤ¶ ......