關於SQL中表的別名使用注意事項

2021-05-28 06:24:10 字數 1102 閱讀 8590

1.在sql語句中一旦指定了表別名,則

不能再使用"表名稱.列名"格式,

只能使用"

表別名.列名

"格式來引用列.

2.在sql主句中使用子查詢中的列時,必須為子查詢指定乙個表別名,然後以"表別名.列名"的格式來應用子查詢中的列.當sql主句的from子句僅為乙個子查詢時,必須為該子查詢指定乙個表別名,否則sql語句無法執行.例如:

select id from

(select e.id from employee as e  where (e.年度 = 2000) and (e.月份 = 3))

select id from

(select e.id from employee as e  where (e.年度 = 2000) and (e.月份 = 3)) as x

3.子查詢中使用了"表別名.列名"來引用列時,若此表別名在子查詢和sql主句中都不存在,則導致sql語句無法執行.例如:

select id from

(select e.id from employee  where (e.年度 = 2000) and (e.月份 = 3)) as x

如果sql主句中存在此表別名,則錯誤不會發生,但會導致無法預料的結果(通常導致該子查詢返回結果為空).例如:

select e.* from (select * from sales as e where (e.年度 = 2006) and (e.月份 = 3)) as e 

where (e.員工號 not in

(select e.員工號 from sales  where (e.年度 = 2000) and (e.月份 = 3))

)此sql語句執行後,導致主句的where子句的子查詢返回空值,使where子句結果為真,篩選實效.

正確的為:

select e.* from (select * from sales as e where (e.年度 = 2006) and (e.月份 = 3)) as e 

where (e.員工號 not in

(select e.員工號 from sales as e where (e.年度 = 2000) and (e.月份 = 3))

)

關於better scroll的使用注意事項

1.動態載入資料需要重新整理滾動區域 this.nexttick 2.滾動區域上的事件,需要在註冊滾動的時候,新增 click true mounted 3.預設 y軸 滾動,需要x軸滾動,新增 scrollx true 4.上拉載入功能,註冊時需要申明,pullupload 可以為true 或者如...

關於primarykey 和key的注意事項

mysql create table exchange id int not null auto increment,abbrev varchar 32 not null,name varchar 255 not null,primary key id 注意 key和 id 之間沒有空格 query...

關於stl標準容器中的迭代器的使用注意事項

很多時候會這麼寫 std mapmmapitem for auto it mmapitem.begin it mmapitem.end it 一般情況下不會出錯 但是如果在迴圈裡面對mmapitem做一些操作,比如刪除的時候,it的計算結果就會出錯 因此如果在迴圈中有可能會做刪除操作的時候這樣寫會比...