如何將第一個(gè)表用SQL語句創(chuàng)建出第二個(gè)表?急急急!!!
將第二個(gè)表的結(jié)構(gòu)說清楚,和第一個(gè)表什么關(guān)系?第二個(gè)中要求有什么數(shù)據(jù)?
你選擇的時(shí)候 用Select 只選擇你需要的字段就行了
你猜有人能看懂什么意思么?
你是只要這特定的幾行呢?還是要把這樣的規(guī)律運(yùn)用到整張表上?
select "21","30","31","40","41","50","51","60","61","70","71","80","81","90","91","0120","0121","01230" from t where id=367
union all
select "20","21","30","31","40","41","50","51","60","61","70","71","80","81","90","91","0120","0121" from t where id=368
union all
select "11","20","21","30","31","40","41","50","51","60","61","70","71","80","81","90","91","0120" from t where id=369
union all
select "10","11","20","21","30","31","40","41","50","51","60","61","70","71","80","81","90","91" from t where id=370
union all
select "01","10","11","20","21","30","31","40","41","50","51","60","61","70","71","80","81","90" from t where id=371
union all
select "00","01","10","11","20","21","30","31","40","41","50","51","60","61","70","71","80","81" from t where id=372
求sql語句, 聯(lián)合兩個(gè)表查詢,建立一個(gè)新表,如何實(shí)現(xiàn)?
有A和B兩個(gè)表,合并為一張新表AB(不要視圖),并增加兩個(gè)字段(運(yùn)費(fèi)結(jié)算和狀態(tài),并可以修改)。rn要求:修改A、B表時(shí),AB表也自動(dòng)更新。rnA表字段及記錄如下:rn---------------------------------------rnID 發(fā)貨單號(hào) 日期 價(jià)格rn309 P001 2012-6-1 100rn.rn.rn.rnB表字段及記錄如下:rn---------------------------------------rnID 存貨名稱 數(shù)量rn309 鉛筆 5rn309 橡皮 9rn.rn.rn.rn合成后的AB表字段及記錄應(yīng)該如下:rn-------------------------------------------------------------------------------rnID 發(fā)貨單號(hào) 日期 價(jià)格 存貨名稱 數(shù)量 運(yùn)費(fèi)結(jié)算 狀態(tài)rn309 P001 2012-6-1 100 鉛筆 5 rn309 P001 2012-6-1 100 橡皮 9rn.rn.rn.select A.ID,A.發(fā)貨單號(hào),A.日期,A.價(jià)格,B.存貨名稱,B.數(shù)量,0 as 運(yùn)費(fèi)結(jié)算,0 as 狀態(tài)
into AB from A inner join B on A.ID=B.ID
根據(jù)你運(yùn)費(fèi)結(jié)算和狀態(tài)的類型,可以定義成''空來代替0
create proc st_jsjbj
as
insert into AB select A.發(fā)貨單號(hào),A.日期,A.價(jià)格,B.存貨名稱,B.數(shù)量 from A inner join B on A.Id=B.id
go
alter table AB add 運(yùn)費(fèi)結(jié)算 varchar(20) null,狀態(tài) varchar(20) null
execute st_jsjbj
你試試
不知道為什么要這樣做,有疑問:
1.既然是關(guān)系型數(shù)據(jù)庫,為什么還要個(gè)合并AB表(假設(shè)稱C表)的Table出現(xiàn)。
2.既然A,B表發(fā)生更改,C表也改變,又為何不要view來做?
3.增加的兩個(gè)欄位 運(yùn)費(fèi)結(jié)算 狀態(tài) 為何不直接不放在A表呢?
如果非得這樣做的話,Oracle數(shù)據(jù)庫,你可以
create table C as
( select a.ID, a.發(fā)貨單號(hào), a.日期, a.價(jià)格
b.存貨名稱,b. 數(shù)量,
null 運(yùn)費(fèi)結(jié)算,null 狀態(tài)
from a,b
where a.id=b.id(+)
);
再將A,B對(duì)應(yīng)寫一個(gè)Trigger(觸發(fā)器)來改變C表
總之,這種方式我怎么也想不通
請(qǐng)用sql語言寫出創(chuàng)建2張表的sql語句
假設(shè)第一個(gè)表表名為a,第二個(gè)為b;
1)select
a.姓名,b.借書證號(hào),a.圖書號(hào),a.借閱時(shí)間
from
a
inner
join
b
on
a.借書證號(hào)=b.借書證號(hào)
and
b.系別='電子商務(wù)';
2)select
b.姓名,a.圖書號(hào),a.借書證號(hào),b.系別
from
a,b
where
a.借書證號(hào)
in
(select
借書證號(hào)
from
a
where
借閱時(shí)間<2002/11/30);
第一個(gè)用的連接查詢即:inner
join
第二個(gè)用的嵌套查詢即:in
(select
借書證號(hào)
from
a
where
借閱時(shí)間<2002/11/30);
怎么用sql語句建立以兩個(gè)字段為主鍵的表
create table t1(pk1 int,pk2 nvarchar(10),name nvarchar(10),val int, primary key(pk1,pk2))
相關(guān)推薦:
電子合同糾紛解決(簽電子合同糾紛怎么解決)
現(xiàn)戶籍所在地怎么填寫(戶籍所在地怎么填寫)
超生新生兒如何上戶(超生如何給孩子上戶口)
行政處罰會(huì)留案底嗎(行政處罰決定書會(huì)留案底嗎)
公民如何保護(hù)生命健康權(quán)(法律如何保護(hù)我們的健康)