SQL select
--desc ±íÃû ÃèÊö±íµÄÄÚÈÝ
desc emp;
--¼ÓÉÏÊýѧ±í´ïʽºÍÁÐÃû ""±£³Ö¸ñʽ
select ename "name space", sal*12 year_sal from emp;
select 2*3 from dual;
select sysdate from dual;
--¿ÕÖµµÄÊýѧ±í´ïʽ ½á¹û¶¼ÊÇ¿ÕÖµ
select ename, sal*12 + comm from emp;
--"||"×Ö·û´®Á¬½Ó µ¥ÒýºÅÖеÄÊÇ×Ö·û´®£¬×Ö·û´®Öеĵ¥ÒýºÅ£¬''±íʾ
select ename||sal from emp;
--distinct ÐÞÊÎÁ½¸ö×Ö¶Î
select distinct deptno, job from emp;
select ename, sal from emp where sal between 800 and 1500;
select ename, sal from emp where sal >= 800 and sal <= 1500;
select ename, sal from emp where comm is null;
--Ò»¸öÊÂÎñ¿ªÊ¼ÓÚÒ»ÌõddlÓï¾ä£¬½áÊøÓïrollback commit ddlÊý¾Ý¶¨ÒåÓï¾ä dclÊý¾Ý¿ØÖÆÓï¾äÓï¾ä
--Õý³£¶Ï¿ªÁ¬½Ó Ìá½» ·ÇÕý³£¶Ï¿ªÁ¬½Ó »Ø¹ö
select ename, sal from emp where sal not in (800 ,1500);
-- Ä£ºý²éѯ
select ename, sal from emp where ename like '_A%';
select ename, sal from emp where ename like '%\%%';
--תÒå×Ö·û
select ename, sal from emp where ename like '%$%%' escape '$';
--ÅÅÐò
select * from dept order by deptno desc;
select ename, sal from emp order by deptno asc, ename desc;
--º¯Êý
select lower(ename) from emp;
select substr(ename,1,3) from emp;
select round(23.652, 1) from dual;
select to_char(sal, '$99,999.999') from emp;
select to_char(sal, 'L000,000.000') from emp;
select to_char(hiredate, 'yyyy-mm-dd hh:mi:ss') from emp;
select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') from dual;
select ename, hiredate from emp
where hiredate > to_date('1982-09-11 12:44:44', 'YYYY-MM-DD HH24:MI:SS');
select sal from emp where sal > to_number('$1,250.000', '$9,999.000');
select ename,sal*12 + nvl(comm, 0) from emp;
--×麯Êý ¶àÐÐÊäÈ룬ֻÓÐÒ»ÐÐÊä³ö select ename, max(sal) from emp; ½á¹û²»Äܱ£Ö¤Ö»ÓÐÒ»ÐÐ
select max(sal) from emp;
select sum(sal) from emp;
select count(distinct deptno) from emp;
--·Ö×麯Êý
select deptno,avg(sal) from emp group by deptno;
select deptno, job, max(sal
Ïà¹ØÎĵµ£º
ÊìϤSQL SERVER 2000µÄÊý¾Ý¿â¹ÜÀíÔ±¶¼ÖªµÀ£¬ÆäDTS¿ÉÒÔ½øÐÐÊý¾ÝµÄµ¼Èëµ¼³ö£¬Æäʵ£¬ÎÒÃÇÒ²¿ÉÒÔʹÓÃTransact-SQLÓï¾ä½øÐе¼Èëµ¼³ö²Ù×÷¡£ÔÚTransact-SQLÓï¾äÖУ¬ÎÒÃÇÖ÷ҪʹÓÃOpenDataSourceº¯Êý¡¢OPENROWSET º¯Êý£¬¹ØÓÚº¯ÊýµÄÏêϸ˵Ã÷£¬Çë²Î¿¼SQLÁª»ú°ïÖú¡£ÀûÓÃÏÂÊö·½·¨£¬¿ÉÒÔÊ®·ÖÈÝÒ×µØʵÏÖSQL SERVER¡¢ACCESS¡¢EXCELÊý¾Ýת»»£ ......
Use equality first.
ʹÓõÈÁ¬½Ó
Use range operators only where equality does not apply.
Ö»ÓÐÔÚµÈÁ¬½Ó²»¿ÉÓõÄÇé¿öÏÂÊÂÓÉÇø¼äÁ¬½Ó
Avoid use of negatives in the form of !=
or NOT.
±ÜÃâʹÓà £¡= »òÕß not
Avoid LIKE pattern matching.
±ÜÃâʹÓà LIKEÆ¥Åä
Try to retrieve specific rows and in small n ......
Îı¾ nvarchar(n)
±¸×¢ ntext
Êý×Ö(³¤ÕûÐÍ) int
Êý×Ö(ÕûÐÍ) smallint
Êý×Ö(µ¥¾«¶È) real
Êý×Ö(Ë«¾«¶È) float
Êý×Ö(×Ö½Ú) tinyint
»õ±Ò money
ÈÕÆÚ smalldatetime
²¼¶û bit
¸½£º×ª»»³ÉSQLµÄ½Å±¾¡£
ALTER TABLE tb ALTER COLUMN aa Byte Êý×Ö[×Ö½Ú]
ALTER TABLE tb ALTER COLUMN aa Long Êý×Ö[³¤ÕûÐÍ]
ALTER T ......
1.bzscs(ɳ³æ ÎÒ°®Ð¡ÃÀ)Óú¯數µÄºÃ辦·¨:
CREATE function [dbo].[calc_date](@time smalldatetime,@now smalldatetime)
returns nvarchar(10)
as
begin
declare @year int,@month int,@day int
select @year = datediff(yy,@time,@now)
if (month(@now)=month(@time)) and (day ......
''' <summary>
''' SQLÎÄ執ÐÐ結¹û¤ÎEXCEL³öÁ¦
''' </summary>
''' <param name="connString">OLEDB½Ó続ÎÄ×ÖÁÐ</param>
''' <param name="sqlString">SQLÎÄ</param>
''' <param name="savePath">³öÁ¦¥Õ¥¡¥¤¥ë¥Ñ¥¹</param>
......