SQL語句寫多個表記錄,和修改多個表記錄
插入
create trigger insert_t on A for insert
as
declare @a int,@b int,@c int
select @a=a,@b=b,@c=c from inserted
insert into B values(@a,@b,@c)
更新
create trigger update_t on A for update
as
declare @a int,@b int,@c int
select @a=a,@b=b,@c=c from inserted
update B set E=@a,D=@b,F=@c where 條件
SQL多表查詢多個字段
數據庫有好幾個表,查詢數據有幾種方法,假定數據結構為:id,字段1,字段2,字段3,其他字段數據表分別為 table1,table2,table31、將三個表的不同的數據合并 select 字段1,字段2,字段3 from table1 union select 字段1,字段2,字段3 from table2 union select 字段1,字段2,字段3 from table32、將三個表的數據合并 select 字段1,字段2,字段3 from table1 union all select 字段1,字段2,字段3 from table2 union all select 字段1,字段2,字段3 from table33、根據某一檢索條件將三個表中的數據橫向排列 比較復雜,且不知結構,做個簡單的,2個表的 假定將 table1,table2 兩個表中 id 相同的數據列出來:select table1.字段1,table1.字段2,table1.字段3, table2.字段1,table2.字段2,table2.字段3 from table1,table2 where *=* 4、其他更加復雜的。
。. 不知是否能解釋明白,如有問題,可直接給我發送信息,需將你的詳細需求說明白。
SQL多表查詢語句
1. select count(*) from 成績表 where 成績<80
* avg(成績) from 成績表 where 課程號=數學課的課程號
* count(*) from 學生表 group by 專業名
* top 3 b.* from 成績表 a,學生表 b where a.學號=b.學號 and 課程號=計算機課程號 order by 成績 desc
顯示不及格的專業所在表的所有信息
select b.* from 成績表 a,專業表 b where a.學號=
(select 學號 from 學生表 where 姓名='李明')
and a.課程號=b.課程號 and a.成績<60
至于要判斷不及格就顯示提示信息的話那個要用到存儲過程,那個我也有點忘了,就沒辦法幫你了
你網上找找存儲過程的使用吧,應該可以找到的
SQL多表查詢語句怎么寫
SQL多表查詢語句的步驟如下:
我們需要準備的材料分別是:電腦、sql查詢器。
1、首先,打開sql查詢器,連接上相應的數據庫表,例如m1表和m2表。
2、點擊“查詢”按鈕,輸入:select max(km) from m1 join m2 on *=* where id=14 and lx=15;。
3、點擊“運行”按鈕,此時查詢到km的最大值為20。
求高手SQL語句,多個表的查詢更新語句
--樓主我幫你寫吧
--有什么疑問可以隨時找我 希望采納
declare @i dec(12,2)
declare @j dec(12,2)
select @i=Score from a
select @j=SUM(Score) from (
select Score from b
union all
select Score from c
union all
select Score from d
union all
select Score from e
union all
select Score from f
union all
select Score from g) aa
if @i@j
begin
update a set *=1
end
--樓主如果想封裝成過程 如下
create proc usp_updateA
as
begin
declare @i dec(12,2)
declare @j dec(12,2)
select @i=Score from a
select @j=SUM(Score) from (
select Score from b
union all
select Score from c
union all
select Score from d
union all
select Score from e
union all
select Score from f
union all
select Score from g) aa
if @i@j
begin
update a set *=1
end
end