Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

35Ìõ»ù±¾SQLÓï¾ä

 1¡¢²éÕÒÔ±¹¤µÄ±àºÅ¡¢ÐÕÃû¡¢²¿ÃźͳöÉúÈÕÆÚ£¬Èç¹û³öÉúÈÕÆÚΪ¿ÕÖµ£¬ÏÔʾÈÕÆÚ²»Ïê,²¢°´²¿ÃÅÅÅÐòÊä³ö,ÈÕÆÚ¸ñʽΪyyyy-mm-dd¡£
select
emp_no,emp_name,dept,isnull(convert(char(10),birthday,120),'ÈÕÆÚ²»Ïê') birthday
from employee
order by dept
 
¡¡¡¡
2¡¢²éÕÒÓëÓ÷×ÔÇ¿ÔÚͬһ¸öµ¥Î»µÄÔ±¹¤ÐÕÃû¡¢ÐԱ𡢲¿ÃźÍÖ°³Æ
select emp_no,emp_name,dept,title
from employee
where emp_name<>'Ó÷×ÔÇ¿' and dept in
(select dept from employee
where emp_name='Ó÷×ÔÇ¿') 
¡¡¡¡
3¡¢°´²¿ÃŽøÐлã×Ü£¬Í³¼ÆÃ¿¸ö²¿ÃŵÄ×ܹ¤×Ê
select dept,sum(salary)
from employee
group by dept
 
¡¡¡¡
4¡¢²éÕÒÉÌÆ·Ãû³ÆÎª14´çÏÔʾÆ÷ÉÌÆ·µÄÏúÊÛÇé¿ö£¬ÏÔʾ¸ÃÉÌÆ·µÄ±àºÅ¡¢ÏúÊÛÊýÁ¿¡¢µ¥¼ÛºÍ½ð¶î
select a.prod_id,qty,unit_price,unit_price*qty totprice
from sale_item a,product b
where a.prod_id=b.prod_id and prod_name='14´çÏÔʾÆ÷' 
¡¡¡¡
5¡¢ÔÚÏúÊÛÃ÷ϸ±íÖа´²úÆ·±àºÅ½øÐлã×Ü£¬Í³¼ÆÃ¿ÖÖ²úÆ·µÄÏúÊÛÊýÁ¿ºÍ½ð¶î
select prod_id,sum(qty) totqty,sum(qty*unit_price) totprice
from sale_item
group by prod_id
 
¡¡¡¡
6¡¢Ê¹ÓÃconvertº¯Êý°´¿Í»§±àºÅͳ¼ÆÃ¿¸ö¿Í»§1996ÄêµÄ¶©µ¥×ܽð¶î
select cust_id,sum(tot_amt) totprice
from sales
where convert(char(4),order_date,120)='1996'
group by cust_id 
¡¡¡¡
7¡¢²éÕÒÓÐÏúÊۼǼµÄ¿Í»§±àºÅ¡¢Ãû³ÆºÍ¶©µ¥×ܶî
select a.cust_id,cust_name,sum(tot_amt) totprice
from customer a,sales b
where a.cust_id=b.cust_id
group by a.cust_id,cust_name 
¡¡¡¡
8¡¢²éÕÒÔÚ1997ÄêÖÐÓÐÏúÊۼǼµÄ¿Í»§±àºÅ¡¢Ãû³ÆºÍ¶©µ¥×ܶî
select a.cust_id,cust_name,sum(tot_amt) totprice
from customer a,sales b
where a.cust_id=b.cust_id and convert(char(4),order_date,120)='1997'
group by a.cust_id,cust_name 
¡¡¡¡
9¡¢²éÕÒÒ»´ÎÏúÊÛ×î´óµÄÏúÊۼǼ
select order_no,cust_id,sale_id,tot_amt
from sales
where tot_amt=
(select max(tot_amt)
from sales) 
¡¡¡¡
10¡¢²éÕÒÖÁÉÙÓÐ3´ÎÏúÊÛµÄÒµÎñÔ±Ãûµ¥ºÍÏúÊÛÈÕÆÚ
select emp_name,order_date
from employee a,sales b
where emp_no=sale_id and a.emp_no in
(select sale_id
from sales
group by sale_id
having count(*)>=3)
order by emp_name 
¡¡¡


Ïà¹ØÎĵµ£º

µ÷ÓÃSQLº¯ÊýÀ´ÊµÏÖºº×ÖÄ£ºý²éѯ

ÔÚsqlÖд´½¨Óû§×Ô¶¨Ò寴Òôº¯Êý£º
create function f_GetPy(@Str nvarchar(400))
returns nvarchar(4000)
as
begin
declare @strlen int,@re nvarchar(4000)
declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1))
insert @t select 'ß¹','A' union all select '°Ë','B'
union all select 'àê ......

Sql Server ²éѯsqlÖ´Ðи÷¸ö½×¶ÎµÄʱ¼ä

Sql Server ²éѯsqlÖ´Ðи÷¸ö½×¶ÎµÄʱ¼ä
set statistics io on
set statistics time on
set statistics profile on
go
[ÄãµÄsqlÓï¾ä]
go
set statistics io off
set statistics time off
set statistics profile off

ÎÒÔËÐУº
set statistics io on
set statistics time on
set statistics profile on ......

ÈçºÎ´´½¨ SQL Server 2005 ÐÂÕË»§£¿


ÈçºÎ´´½¨ SQL Server 2005 ÐÂÕË»§£¿
Ê×ÏÈÒªÉèÖÃSQL Server 2005µÄ·ÃÎÊ·½Ê½
1´ò¿ªSQL Server Management Studio
2·þÎñÆ÷Ãû³ÆÉÏÓÒ¼üÑ¡Ôñ“ÊôÐÔ”£¬´ò¿ª“·þÎñÆ÷ÊôÐÔ”¶Ô»°¿ò£¬ÔÚ“Ñ¡ÔñÒ³”ÀïÑ¡Ôñ“°²È«ÐÔ”£¬ÔÚ“·þÎñÆ÷Éí·ÝÑéÖ¤”ÀïÑ¡Ôñ“SQL ServerºÍWindows É ......

SQL Server 2005 ·þÎñÆ÷½ÇÉ«ºÍÊý¾Ý¿â½ÇÉ«ÃûÈ«½â

SQL Server 2005 ·þÎñÆ÷½ÇÉ«ºÍÊý¾Ý¿â½ÇÉ«ÃûÈ«½â
/*·þÎñÆ÷½ÇÉ«*/
sysadmin
--ÔÚ SQL Server ÖнøÐÐÈκλ¡£¸Ã½ÇÉ«µÄȨÏÞ¿çÔ½ËùÓÐÆäËü¹Ì¶¨·þÎñÆ÷½ÇÉ«¡£
serveradmin
--ÅäÖ÷þÎñÆ÷·¶Î§µÄÉèÖá£
setupadmin
--Ìí¼ÓºÍɾ³ýÁ´½Ó·þÎñÆ÷£¬²¢Ö´ÐÐijЩϵͳ´æ´¢¹ý³Ì£¨Èç sp_serveroption£©¡£
securityadmin
--¹ÜÀí·þÎñÆ÷ ......

SQLÖбí±äÁ¿ºÍÁÙʱ±íµÄÓÅȱµã

http://www.cnblogs.com/Mainz/archive/2008/12/20/1358897.html
ʲôÇé¿öÏÂʹÓñí±äÁ¿£¿Ê²Ã´Çé¿öÏÂʹÓÃÁÙʱ±í£¿
±í±äÁ¿£º
DECLARE @tb  table(id   int   identity(1,1), name   varchar(100))
INSERT @tb
SELECT id, name
from mytable
WHERE name like ‘zhang%&rsquo ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ