SQL學習總結(二)

2021-04-27 23:09:39 字數 1511 閱讀 9588

select 語句加where子句(條件限制)

1.limiting rows using a selection

select * from emp where deptno=30;

select * from emp where ename='king';

2.comparison conditions

select * from emp where sal>2500;

3.other comprison conditions

a)using between

select * from emp where sal between 900 and 2000;

b)using in 

select * from emp where mgr in(7698,7788);

c)using like(%可以代表任意多個字元,而_代表任一字元)

select * from emp where ename like 'a%';

select * from emp where ename like '_a%';

d)using null

select * from emp where mgr is null;

4. logical conditions

a) using the and operator

select * from emp where  sal>1000 and job like '%man%';

b) using the or operator

select * from emp where  sal>1000 and job like '%man%';

c) using the not operator

select * from emp where job not in ('salesman','clerk');

5.rules of precedence (注意下面兩種情況是不同的)

select * from emp where job='salesman' or job='clerk'  and sal >=1300;

select * from emp where (job='salesman' or job='clerk')  and sal >=1300;

order by子句 預設的是按asc排序

1. select * from emp order by hiredate;

2. sorting in descending order

select * from emp order by hiredate desc;

3. sorting by column alias

select ename,sal,12*sal annsal from emp order by annsal;

4. sorting by multiple columns

select ename,deptno,sal annsal from emp order by deptno,sal desc;

學習總結 SQL學習總結之SQL語法

選取所有列即原表返回 select from table name 例如 select distinct country from websites 例如 從 websites 表中選取國家為 cn 的所有 例如 從 websites 表中選取id為1的所有 文字字段 vs.數值字段 where 子...

SQL注入總結(二)

手工注入的大致思路 判斷是否存在注入,注入是字元型還是數字型 猜解sql查詢語句中的字段數 order by 2 確定顯示的字段順序 union select 1,2 獲取當前資料庫 union select 1,database 獲取資料庫中的表 xx union select 1,table n...

SQL之總結(二)

4.關於取兩個日期之間的年份 ceil months between sysdate,c.sendtime 12 worktime ceil n 取大於等於n的最小整數 floor n 取小於等於n的最大整數 5.如果某個欄位為空值則以 nbsp 代替 nvl c.phone,18677777777...