關於連線查詢的一些看法

2021-04-13 09:13:35 字數 1569 閱讀 5202

正確的

select a.name,a.stuno,sum(b.score) from student a , score b where a.stuno=b.stuno(+) and b.stuno(+)=2 group by a.name,a.stuno;

select a.name,a.stuno,sum(b.score) from student a left outer join  score b on a.stuno=b.stuno and b.stuno=2 group by a.name,a.stuno; 

錯誤的select a.name,a.stuno,sum(b.score) from student a left outer join  score b on a.stuno=b.stuno where b.stuno=2 group by a.name,a.stuno;

**********=

結論:where 會產生篩選,on只是連線條件.

select a.a,b.b

from a,b

where a.a=b.a(+)

and b.c(+)>10

你的寫發是對的, 左連線失效不同於where a.a=b.a

具體如下:

sql> select * from a;

a----------12

34sql> select * from b;

a b c

---------- ---------- ----------

1 4 10

2 5 11

5 6 12

6 7 13

sql>select a.a,b.a,b.b,b.c

from a,b

where a.a=b.a;

a a b c

---------- ---------- ---------- ----------

1 1 4 10

2 2 5 11

sql>select a.a,b.a,b.b,b.c

from a,b

where a.a=b.a(+);

a a b c

---------- ---------- ---------- ----------

1 1 4 10

2 2 5 11

3 4

sql>select a.a,b.a,b.b,b.c

from a,b

where a.a=b.a(+) and b.c>10;

a a b c

---------- ---------- ---------- ----------

2 2 5 11

sql>select a.a,b.a,b.b,b.c

from a,b

where a.a=b.a(+) and b.c(+)>10; /*這種方法有必要嗎?*/

a a b c

---------- ---------- ---------- ----------

1 2 2 5 113 4

意思不一樣

有(+)的是連線條件

不帶的是對連線結果過濾。

關於連線查詢的一些看法

正確的 select a.name,a.stuno,sum b.score from student a score b where a.stuno b.stuno and b.stuno 2 group by a.name,a.stuno select a.name,a.stuno,sum b.s...

關於連線查詢 join left join

進行連線查詢時,先保證待連線表的 engine 和default charset 保持一致 可有效提速 保證 on 條件列的索引 重要!列出表的資訊 show create table table name show index from table name mysql的關聯演算法是 nest l...

C 關於陣列的一些看法

本來想等我完全學完c 再好好一些篇心得總結,還有歸納好c 的一些常用知識點。但是今天看看了陣列,雖然學習c語言的時候,陣列也學得差不多,但是今天學到了一些新的知識點,覺得非常有用,就忍不住寫下來了。其次對元素的賦值。可以是 int a 3 初始化便賦值 也可以 int a 3 a 0 1 a 1 2...