複製表結構以及資料:
create table new as select * from old
複製資料到乙個相同的表:
insert into sametable select * from old
只複製表結構:
create table new as select * from old where 1 = 2
查詢某個節點下面的所有子節點select * from tb_deptconfig start with parent_id = -1 connect by prior id = parent_id
查詢某個節點上面的所有父節點select * from tb_dept start with id = '44060' connect by prior parent_id = id;
查詢某個節點的根節點select name,connect_by_root(name),connect_by_root(id) from tb_deptconfig start with id = '440600000094' connect by prior parent_id = id;
查詢某個節點的所有葉子節點select * from tb_deptconfig where connect_by_isleaf = 1 start with parent_id = '-1' connect by parent_id =prior id;
查詢某個節點的父親節點路徑select name,sys_connect_by_path(name,'--') from tb_deptconfig start with id = '44060' connect by prior parent_id = id;
查詢某個節點的子節點路徑select name,sys_connect_by_path(name,'--') from tb_deptconfig start with parent_id = -1 connect by prior id = parent_id
case when表示式(case when b.oritation = '0'
then 100
case when b.oritation = '1'
then 200
else 300) as id
ege:
select
b.[_id] ,
b.orientation,
c.[user_id],
from record b
left join
(select user_id,name from contact
union
select user_id,name from friendcontact) c
on (case when b.orientation = '0' then 10
else b.[user_id] end ) = c.[user_id]
where b.[user_id]= "+muserid +
" order by b.receive_time desc "
有ab表,a表資料完整,將a表的某些字段更新到b中
update b set b(b1,b2,b3) = (select a1,b2,b3 from a,b where a.id = b.id)
Sql高階語法
插入語句 通常寫法 insert into 列1,列2.values 值1,值2.錯誤示範 insert into tb2 select from tb1 錯誤資訊 僅當使用了列列表並且 identity insert 為 on 時,才能為表中的標識列指定顯式值 其他 正確示範 這裡必須要指定列名 ...
SQL語句高階語法
本文仍然使用之前的表 限制選擇 select from star limit 從star表中選取前兩條記錄 sql link select from star where province like 武 選取province以武字開始的左右使用者 select from star where pro...
SQL語法(2高階入門之表關聯)
多表關聯的話表之間必須得存在關係才行,需要建立 外來鍵 約束 關係表中插入主表的主鍵做外來鍵。案列分析 需求 有使用者表sys user和角色表sys role,則建乙個把使用者與角色關聯起來的關係表我們稱之為使用者角色表sys userrole 那麼我們就可以用以下語句查詢每個使用者分別具備哪些角...