Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.2.0
Connected as test@MSGDE
SQL>
SQL> col id format a10;
SQL> col name format a10;
SQL> col rq format a10;
SQL> create table a(id int, name varchar(10), rq int);
Table created
SQL> create table b(id int, name varchar(10), rq int);
Table created
SQL> begin
2 insert into a values(1,'a',1);
3 insert into a values(2,'s',1);
4 insert into a values(3,'s',1);
5 insert into a values(4,'a',1);
6 insert into a values(5,'a',1);
7 insert into a values(6,'a',2);
8 insert into a values(7,'s',2);
9 insert into a values(8,'dd',2);
10 end;
11 /
PL/SQL procedure successfully completed
SQL> insert into b
2 select * from a
3 where not exists(select * from a x where a.name =x.name and x.id < a.id);
3 rows inserted
SQL> select * from b order by id ;
ID NAME RQ
---------- ---------- ----------
1 a 1
2 s 1
8 dd 2
SQL> drop table a purge ;
Table dropped
SQL> drop table b purge ;
Table dropped
SQL>
uj5u.com熱心網友回復:
這是結束回圈時的結果
你的邏輯有問題,為什么不把T2表放在外回圈,回圈去找T1表呢
uj5u.com熱心網友回復:
這是求分組最小值,何必多次回圈呢?
select distinct b.name,first_value(a.id) over (partition by a.name order by a.id) from a,b where a.name=b.name;
或
select distinct b.name,min(a.id) over (partition by a.name order by a.id) from a,b where a.name=b.name;
uj5u.com熱心網友回復:
一個分析函式就搞定了 ROW_NUMER ... OVER
要是下次遍歷時,排除已看過的郵件,則可以在第一張表里加上一個閱讀標記
**桔妹導讀:**深耕人工智能領域,致力于探索AI讓出行更美好的滴滴AI Labs再次斬獲國際大獎,這次獲獎的專案是什么呢?一起來看看詳細報道吧! 近日,由國際計算語言學協會ACL(The Association for Computational Linguistics)舉辦的世界最具影響力的機器 ......
我們經常在資料庫中使用 LIKE 運算子來完成對資料的模糊搜索,LIKE 運算子用于在 WHERE 子句中搜索列中的指定模式。 如果需要查找客戶表中所有姓氏是“張”的資料,可以使用下面的 SQL 陳述句: SELECT * FROM Customer WHERE Name LIKE '張%' 如果需要 ......
關于MySQL的二進制日志(binlog),我們都知道二進制日志(binlog)非常重要,尤其當你需要point to point災難恢復的時侯,所以我們要對其進行備份。關于二進制日志(binlog)的備份,可以基于flush logs方式先切換binlog,然后拷貝&壓縮到到遠程服務器或本地服務器 ......