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

³£¼ûsqlÃæÊÔÌâ

/*
½¨±í£º
dept:
deptno(primary key),dname,loc
emp:
empno(primary key),ename,job,mgr,sal,deptno
*/
1 Áгöemp±íÖи÷²¿ÃŵIJ¿Ãźţ¬×î¸ß¹¤×Ê£¬×îµÍ¹¤×Ê
select max(sal) as ×î¸ß¹¤×Ê,min(sal) as ×îµÍ¹¤×Ê,deptno from emp group by deptno;
2 Áгöemp±íÖи÷²¿ÃÅjobΪ'CLERK'µÄÔ±¹¤µÄ×îµÍ¹¤×Ê£¬×î¸ß¹¤×Ê
select max(sal) as ×î¸ß¹¤×Ê,min(sal) as ×îµÍ¹¤×Ê,deptno as ²¿ÃźŠfrom emp where job = 'CLERK' group by deptno;
3 ¶ÔÓÚempÖÐ×îµÍ¹¤×ÊСÓÚ1000µÄ²¿ÃÅ£¬ÁгöjobΪ'CLERK'µÄÔ±¹¤µÄ²¿Ãźţ¬×îµÍ¹¤×Ê£¬×î¸ß¹¤×Ê
select max(sal) as ×î¸ß¹¤×Ê,min(sal) as ×îµÍ¹¤×Ê,deptno as ²¿ÃźŠfrom emp as b
where job='CLERK' and 1000>(select min(sal) from emp as a where a.deptno=b.deptno) group by b.deptno
4 ¸ù¾Ý²¿ÃźÅÓɸ߶øµÍ£¬¹¤×ÊÓеͶø¸ßÁгöÿ¸öÔ±¹¤µÄÐÕÃû£¬²¿Ãźţ¬¹¤×Ê
select deptno as ²¿ÃźÅ,ename as ÐÕÃû,sal as ¹¤×Ê from emp order by deptno desc,sal asc
5 д³ö¶ÔÉÏÌâµÄÁíÒ»½â¾ö·½·¨
£¨Çë²¹³ä£©
6 Áгö'ÕÅÈý'ËùÔÚ²¿ÃÅÖÐÿ¸öÔ±¹¤µÄÐÕÃûÓ벿ÃźÅ
select ename,deptno from emp where deptno = (select deptno from emp where ename = 'ÕÅÈý')
7 Áгöÿ¸öÔ±¹¤µÄÐÕÃû£¬¹¤×÷£¬²¿Ãźţ¬²¿ÃÅÃû
select ename,job,emp.deptno,dept.dname from emp,dept where emp.deptno=dept.deptno
8 ÁгöempÖй¤×÷Ϊ'CLERK'µÄÔ±¹¤µÄÐÕÃû£¬¹¤×÷£¬²¿Ãźţ¬²¿ÃÅÃû
select ename,job,dept.deptno,dname from emp,dept where dept.deptno=emp.deptno and job='CLERK'
9 ¶ÔÓÚempÖÐÓйÜÀíÕßµÄÔ±¹¤£¬ÁгöÐÕÃû£¬¹ÜÀíÕßÐÕÃû£¨¹ÜÀíÕßÍâ¼üΪmgr£©
select a.ename as ÐÕÃû,b.ename as ¹ÜÀíÕß from emp as a,emp as b where a.mgr is not null and a.mgr=b.empno
10 ¶ÔÓÚdept±íÖУ¬ÁгöËùÓв¿ÃÅÃû£¬²¿Ãźţ¬Í¬Ê±Áгö¸÷²¿ÃŹ¤×÷Ϊ'CLERK'µÄÔ±¹¤ÃûÓ빤×÷
select dname as ²¿ÃÅÃû,dept.deptno as ²¿ÃźÅ,ename as Ô±¹¤Ãû,job as ¹¤×÷ from dept,emp
where dept.deptno *= emp.deptno and job = 'CLERK'
11 ¶ÔÓÚ¹¤×ʸßÓÚ±¾²¿ÃÅƽ¾ùˮƽµÄÔ±¹¤£¬Áгö²¿Ãźţ¬ÐÕÃû£¬¹¤×Ê£¬°´²¿ÃźÅÅÅÐò
select a.deptno as ²¿ÃźÅ,a.ename as ÐÕÃû,a.sal as ¹¤×Ê from emp as a
where a.sal>(select avg(sal) from emp as b where a.deptno=b.deptno) order by a.deptno
12 ¶ÔÓÚemp£¬Áгö¸÷¸ö²¿ÃÅÖÐƽ¾ù¹¤×ʸßÓÚ±¾²¿ÃÅƽ¾ùˮƽµÄÔ±¹¤ÊýºÍ²¿Ãź


Ïà¹ØÎĵµ£º

SQL·ÖÒ³²éѯ

·ÖÒ³sql²éѯÔÚ±à³ÌµÄÓ¦Óúܶ࣬Ö÷ÒªÓд洢¹ý³Ì·ÖÒ³ºÍsql·ÖÒ³Á½ÖÖ£¬ÎұȽÏϲ»¶ÓÃsql·ÖÒ³£¬Ö÷ÒªÊǺܷ½±ã¡£ÎªÁËÌá¸ß²éѯЧÂÊ£¬Ó¦ÔÚÅÅÐò×Ö¶ÎÉϼÓË÷Òý¡£sql·ÖÒ³²éѯµÄÔ­ÀíºÜ¼òµ¥£¬±ÈÈçÄãÒª²é100ÌõÊý¾ÝÖеÄ30-40Ìõ£¬ÄãÏȲéѯ³öÇ°40Ìõ£¬ÔÙ°ÑÕâ30Ìõµ¹Ðò£¬ÔÙ²é³öÕâµ¹ÐòºóµÄÇ°Ê®Ìõ£¬×îºó°ÑÕâÊ®Ìõµ¹Ðò¾ÍÊÇÄãÏëÒªµÄ½á¹û¡£
   ......

sqlÏÈÅÅÐòºó·Ö×éµÄʵÏÖ

ÓÐÕâÑùÒ»¸öÊý¾Ý¿â±í  
  t1             t2           t3……n  
  --------------------------  
  aaa      ......

SQL Server 2005 ¾µÏñ¹¹½¨ÊÖ²á(1)

SQL Server 2005 ¾µÏñ¹¹½¨ÊÖ²á
 
Ò»¡¢ ¾µÏñ¼ò½é
1¡¢ ¼ò½é
Êý¾Ý¿â¾µÏñÊǽ«Êý¾Ý¿âÊÂÎñ´¦Àí´ÓÒ»¸öSQL ServerÊý¾Ý¿âÒƶ¯µ½²»Í¬SQL Server»·¾³ÖеÄÁíÒ»¸öSQL ServerÊý¾Ý¿âÖС£¾µÏñ²»ÄÜÖ±½Ó·ÃÎÊ;ËüÖ»ÓÃÔÚ´íÎó»Ö¸´µÄÇé¿öϲſÉÒÔ±»·ÃÎÊ¡£
Òª½øÐÐÊý¾Ý¿â¾µÏñËùÐèµÄ×îСÐèÇó°üÀ¨ÁËÁ½¸ö²»Í¬µÄSQL ServerÔËÐл·¾³¡£Ö÷·þÎñÆ÷± ......

SQL¾­µäÐÐתÁÐ

--²âÊÔ±í
create table tb_month
(monthid varchar(2),mongthName varchar(50))
insert into tb_month
select '01','Ò»ÔÂ'
union all select '02','¶þÔÂ'
union all select '03','ÈýÔÂ'
union all select '04','ËÄÔÂ'
union all select '05','ÎåÔÂ'
union all select '06','ÁùÔÂ'
union all select '07','ÆßÔÂ'
......

SQL Óï¾ä´óÈ«

Ò»¡¢»ù´¡
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
Create DATABASE database-name
2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database dbname
3¡¢ËµÃ÷£º±¸·Ýsql server
--- ´´½¨ ±¸·ÝÊý¾ÝµÄ device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ