在SQL Server如何在幾個表裡面查詢資料問題如下

2022-03-19 19:35:26 字數 4765 閱讀 5165

1樓:

--1、查詢『001』課程比『002』課程成績高的所有學生的學號?

select c1.s# from c c1 join c c2 on c1.s#=c2.

s# where c1.c#='001' and c2.c#='002' and c1.

score>c2.score

--2、查詢平均成績大於60分的同學的學號和平均成績?

select s#,score from c where score>60

--3、查詢沒學過『葉平'老師課的同學的學號、姓名?

select s#,sname from a where s# not in(select s# from c join b on c.c#=b.c# join d on d.

t#=b.t# where tname='葉平')

--4、查詢學過『001』並且也學過編號『002』課程的同學的學號、姓名?

select s#,sname from a where s# in(select s# from c where c#='001') and s# in(select s# from c where c#='002')

--5、查詢課程編號『002』的成績比課程編號『001』課程低的所有同學的學號、姓名?

select s#,sname from a where s# in(select c1.s# from c c1 join c c2 on c1.s#=c2.

s# where c1.c#='001' and c2.c#='002' and c1.

score>c2.score)

--6、查詢所有課程成績小於60分的同學的學號、姓名?

select a.s#,sname from a join c on a.s#=c.s# where score<60

--7、檢索『004』課程分數小於60,按分數降序排列的同學學號:

select s# from c where c#='004' and score<60 order by score desc

--8、刪除『002』 同學的『001』課程成績?

delete c where s#='002' and c#='001'

2樓:移動引領生活

1、declare @s float

set @s = (select max(score) as s from c where id='002')

select * from c where id ='001' and score > @s

2、select * from c where score >60

3、select * from

(select a.c#,sname,b.t# from

(select c#,sname from a) a

left join

(select c#,t# from b) b

on a.c#=b.#) t

left join

(select * from d where tname='葉平') d

on t.t#=d.t#

where d.y# is null

4、select * from a where s# in (select s# from c where c#='001' and c#='002')

5、參考第一個

6、select * from a where s# in (select s# from c where score <60)

7、select * from c where c#='004' and score <60 order by score desc

8、delete from c where s#='002' and c#='001'

sql server如何在一個資料庫的多個表或多個資料庫的多個表中查詢內容

3樓:飄雨

同庫操作

select a.列名1,b.列名2,a.列名3 from 表名1 as a

join 表名2 as b

on a.關聯欄位=b.關聯欄位

不同庫操作

select a.列名1,b.列名2,a.列名3 from 庫名1.dbo.表名1 as a

join 庫名2.dbo.表名2 as bon a.關聯欄位=b.關聯欄位

2張表以上的多表連線:先兩張連線再與第三張連線,依次下去,如select a.列名1,b.列名2,a.列名3 from 表名1 as a

join 表名2 as b

on a.關聯欄位=b.關聯欄位

join 表名3 as c

on a.關聯欄位=c.關聯欄位

4樓:匿名使用者

一個資料庫的多個表

select a.* ,b.*

from a, b

where a.col1=b.col1

跨多個資料庫的多個表中查詢

select a.* ,b.*

from opendatasource('sqloledb', 'data

source=ip;user id=;password=' ).庫名.dbo.

表名 a, opendatasource('sqloledb', 'data source=ip;user id=;password=' ).庫名.dbo.

表名 b

where a.col1=b.col1

5樓:席翊君

用左連線或者右連線,left join 或者inner join。

sqlserver如何多張表中搜尋某個資料

6樓:流水

這樣的話建議做一個表,定義好哪些表和欄位,然後按著這個表的內容在定義好的表內按照定義好的欄位進行搜尋,不過效率很低。

7樓:匿名使用者

select *

from 表名,表名,.....

where 資料=『1027』

8樓:匿名使用者

可以用全文檢索的方式

推薦使用

lucene搜尋架構來實現

很簡單的

sql server 如何查一個資料庫中有幾張表

9樓:匿名使用者

select * from sysobjects where (xtype = 'u') 查詢當前資料庫下所有使用者建立的表 追問: 麻煩問一下,其中的xtype = 'u' 分別是什麼意思? 回答:

xtype char(2) 物件型別 。可以是下列物件型別中的一種: c = check 約束 d = 預設值或 default 約束 f = foreign key 約束 l = 日誌 fn = 標量函式 if = 內嵌 表函式 p = 儲存過程 pk = primary key 約束(型別是 k) rf = 複製篩選儲存過程 s = 系統表 tf = 表函式 tr = 觸發器 u = 使用者表 uq = unique 約束(型別是 k) v = 檢視 x = 擴充套件儲存過程

10樓:匿名使用者

select count(*) from sysobjects where (xtype = 'u')

11樓:風在夏季轉

你直接在資料庫管理器數有多少張表就可以啦!

sql server 如何查詢一個資料庫下所有表裡的資料

12樓:

右鍵表→編寫表指令碼為→select到(s)→新查詢編輯器視窗→!執行,這表的全部內容就查出來了

13樓:匿名使用者

直接語句可能不太行,只能嘗試用儲存過程/函式去做這個事情。

sql server中如何將如下三個表相連線,所有內容都要完整

14樓:匿名使用者

--假如你的表名依次為 tb1、tb2、tb3

--你理解錯了 tb1肯定是最前的 因為是基本工資 所以他包含所有的員工,以他為主表就可以

--不明白再問我 希望解決了樓主的問題

select tb1.月份, tb1.職工編號,tb1.姓名,tb1.基本工資,tb2.獎懲工資,tb3.加班工資

from tb1 left join tb2 on tb1.職工編號= tb2.職工編號

left join tb3 on tb1.職工編號= tb3.職工編號

15樓:匿名使用者

select t1.月份,t1.職工id,t1.

姓名,t1.基本工資,t1.獎懲工資,t1.

加班工資 from t1(基本工資),t2(獎懲工資),t3(加班工資) where t1.職工id=t2.職工id and t1.

職工id=t3.職工id and t1.月份= t2.

月份 and t1.月份= t3.月份

再對獎懲工資和加班工資加上一個轉換函式,為null的話就轉換為0,oracle裡面是nvl,sql server好像是isnull 你核實下 isnull(t1.獎懲工資,0),isnull(t1.加班工資,0)

16樓:雲天英雄

建立相應表對應關係即可。注意外來鍵的連線。

17樓:匿名使用者

連線需要兩個條件(月份+職工號)

如何在 sql server 2019裡創

使用資料庫嚮導建立資料庫 依次開啟 microsoft sql server 企業管理器 左欄的 資料庫 開啟選單欄的 工具 嚮導 其中的 資料庫 雙擊 建立資料庫嚮導 輸入資料庫檔名稱 demodata 初始大小 50m 點選 下一步 選擇資料庫檔案增長方式,我們可以選擇預設,即不做任何操作,直接...

sql server中如何理解 isnull 列名,0 和

1 isnull 引數1,引數2 判斷引數1是否為null,如果是,返回引數2,否則返回引數1。2 isnull 列名,0 isnull 函式是用來判斷列名是否為null,如果為null,則返回0,否則,返回列名的值。3 是不等號,與!一樣 比如select 3 where 1 2 查出來的結果是3...

在中如何在數字上打鉤,word文件中如何在數字上打鉤 勾是要和數字重疊

1.將游標放在word文件的 任意 位置,切換到 插入 標籤,找到 符號 下拉選單的 其他符號 2.耐心地找到 鉤 的符號,點 插入 3.選中剛插入的 鉤 點選 插入 藝術字 下拉選單,選擇第一個樣式。記住,一定要選中 鉤 再操作。4.彈出對話方塊,全部預設,直接點確定。5.繼續選中 鉤 在 格式 ...