SQL数据库多个表格中,从3个表格中根据条件,提取字段的一个问题
\u5728sql\u4e2d \u80fd\u4e0d\u80fd\u628a\u4ece\u540c\u4e00\u5f20\u8868\u4e2d\uff0c\u6839\u636e\u4e0d\u540c\u7684\u6761\u4ef6\uff0c\u67e5\u8be2\u51fa\u7684\u4e00\u4e2a\u5b57\u6bb5\u7684\u4e0d\u540c\u7684\u503c \u5206\u6210\u51e0\u4e2a\u5217\u663e\u793a\u51fa\u6765\uff1f\u7528\u4e00\u8868\u62c6\u591a\u8868\uff0c\u4e3e\u4f8b\uff1aselect a1.c,a2.c from a a1,a a2
pc_id,screen_id\u54ea\u4e2a\u4f18\u5148\uff1f\u4ee5pc_id\u4f18\u5148\u4e3a\u4f8b\uff1a
oracle\u7528decode\u51fd\u6570\uff0csqlserver\u53ef\u4ee5\u7528case...when\uff0c\u7ed9\u4f60\u4e2aoracle\u7684\u4f8b\u5b50
create procedure add_table
is
begin
insert into wip_led_opration(operation_id,led_pc_id,led_screen_id)
select operation_id,led_pc_id, decode(led_pc_id,null,led_screen_id,null)
-- \u903b\u8f91\uff1a\u7b2c\u4e09\u5217led_screen_id\uff0c\u5148\u5224\u65adled_pc_id\u662f\u5426\u4e3a\u7a7a\uff0c\u4e3a\u7a7a\u5219\u7528led_screen_id\uff0c\u975e\u7a7a\u5373led_pc_id\u5b58\u5728\uff0c\u5219led_screen_id\u5217\u4f4d\u7f6e\u7559\u7a7a
from fnd_led_pc ,fnd_led_screen ,fnd_operation
where fnd_operation.status=1
and fnd_led_screen.status=1
and fnd_led_pc.status=1
-- and fnd_operation.status=fnd_led_screen.status --\u8fd9\u4e2a\u6761\u4ef6\u662f\u591a\u4f59\u7684\uff0c\u4e24\u4e2a\u503c\u90fd=1\u4e86
and fnd_led_screen.status=fnd_led_pc.status ;
end;
/* \u53e6\u5916\u63d0\u51e0\u70b9\u5efa\u8bae
1. \u5efa\u8bae\u7ed9\u4e09\u4e2a\u8868\u52a0\u4e0a\u522b\u540d
2. \u591a\u4f59\u7684\u8fde\u63a5\u6761\u4ef6\u6211\u6ce8\u91ca\u6389\u4e86\uff0c\u867d\u7136\u5bf9\u6267\u884c\u8ba1\u5212\u5e94\u8be5\u6ca1\u6709\u592a\u5927\u5f71\u54cd
3. SELECT\u540e\u6700\u597d\u6807\u8bc6\u51fa\u6e90\u8868\uff0c\u6bd4\u5982fnd_operation.operation_id\uff0c\u8fd9\u6837\u81ea\u5df1\u770b\u7740\u4e5f\u6e05\u695a
*/
具体分析为什么inner join会不显示包装工序。是因为员工表中包装工序没有添加相应的员工。因为在员工表中找不到对应记录。无法显示产品表中这个包装工序。
代码是:select dingdan.chanpinxinghao,gsmx.gxname,dingdan.pingshenhao from dingdan left join gsmx on dingdan.chanpinxinghao=gsmx.chanpinxinghao left join yuangong on gsmx.gxname=yuangong.gxname where dingdan.dangqianzhuangtai="已投产"
select * from 表名 where 条件
补充一下问题吧,我等通知了。
绛旓細select 'a' [table],count(*) [count] from aunion allselect 'b' [table],count(*) [count] from bunion allselect 'c' [table],count(*) [count] from c鍙﹀閯欒妤间笅銆
绛旓細SQL璇彞鏍煎紡锛歴elect 瀛楁1锛屽瓧娈2锛屽瓧娈3 from 琛1锛岃〃2锛岃〃3 where 鏉′欢 渚嬪瓙锛氭煡璇琛ㄤ腑鐨剆no瀛楁锛 c琛ㄤ腑鐨刢no瀛楁锛宩琛ㄤ腑鐨刯no瀛楁 select sno,pno,jno from s,p,j
绛旓細鍙互鐢╟onvert鍑芥暟锛宻elect a=convert(datetime,'12'+'05' +'06',111),杈撳嚭缁撴灉涓2012-05-06 00:00:00.000锛屼綘浣跨敤鏄彲浠ユ妸涓変釜瀛楃涓叉浛鎹㈡垚鐩稿簲鐨勫垪锛屽叾浠栫殑濡傛湁涓嶆槑鐧藉彲鍐嶈仈绯绘垜
绛旓細)鎻掑叆鐨勫瓧娈靛拰鏌ヨ鐨勫瓧娈垫暟閲忕被鍨嬩竴鑷 鐢变簬浣犵殑澶稿簱鏌ヨ鎻掑叆 鎵浠ュ湪琛鍚嶅墠鍔 搴撳悕.鐢ㄦ埛鍚 insert into B.鐢ㄦ埛.DDD(瀛楁1锛屽瓧娈2锛屽瓧娈3 ...)(select 瀛楁1锛屽瓧娈2锛屽瓧娈3 ... from A.鐢ㄦ埛.AAA,A.鐢ㄦ埛.BBB,A.鐢ㄦ埛.CCC )濡傛灉鏄痵qlserver鏁版嵁搴擄紝鍙互鍦ㄦ煡璇㈠垎鏋愬櫒宸﹁竟鑿滃崟鐪嬪埌琛ㄧ敤鎴峰悕锛屽鏋滀綘...
绛旓細1銆佹墦寮鏁版嵁搴撶鐞嗗伐鍏凤紝鍦鏁版嵁搴撲腑鏂板缓涓や釜琛鐢ㄤ簬娴嬭瘯锛岃繖閲岋紝涓や釜琛ㄧ殑琛ㄧ粨鏋勮涓鏍凤紝鍒嗗埆寤虹珛TEST 鍜 TEST1 鐩爣灏辨槸浠嶵EST鑷姩鍐欐洿鏂扮殑鏁版嵁鍒癟EST1涓2銆佸紑鍚柊鐨SQL鏌ヨ绐楀彛锛屽垱寤轰竴涓瓨鍌ㄨ繃绋嬨傛剰鎬濇槸灏唅nsert鍒癟EST涓殑鏁版嵁鎻掑叆鍒癟EST1涓3銆佸崟鍑烩樻墽琛屸欙紝涓涓悕瀛椾负鈥楾鈥欑殑瑙﹀彂灏辨柊寤哄畬鎴愪簡...
绛旓細SQL鏁版嵁搴撲腑,濡備綍鎶婁竴寮琛ㄤ粠涓涓暟鎹簱鎻掑叆鍒板彟涓涓暟鎹簱? 鎴戞潵绛 1涓洖绛 #鐑# 宸插濂虫у氨搴旇鎵挎媴瀹堕噷澶ч儴鍒嗗鍔″悧?鏌忓奖abc123 2018-03-15 路 TA鑾峰緱瓒呰繃1涓囦釜璧 鐭ラ亾灏忔湁寤烘爲绛斾富 鍥炵瓟閲:24 閲囩撼鐜:100% 甯姪鐨勪汉:3.2涓 鎴戜篃鍘荤瓟棰樿闂釜浜洪〉 鍏虫敞 灞曞紑鍏ㄩ儴 鎯呭喌涓:data2琛...
绛旓細鍦‥XCEL涓牴鎹姹傚垎鍒埗浣涓変釜琛鍒嗗埆瀵煎叆灏卞彲浠ヤ簡...琛1 abcde 琛2 abcfg 琛3 bcdhij 鐒跺悗鍦ㄤ紒涓氱鐞嗗櫒鐨勫鍏ヤ竴姝ユ鎿嶄綔鎴栫敤 璇彞濡備笅 --浠嶦xcel鏂囦欢涓,瀵煎叆鏁版嵁鍒SQL鏁版嵁搴撲腑,寰堢畝鍗,鐩存帴鐢ㄤ笅闈㈢殑璇彞:/*===*/ --濡傛灉鎺ュ彈鏁版嵁瀵煎叆鐨勮〃宸茬粡瀛樺湪 insert into 琛 select * from OPENROWSET(...
绛旓細select * from 鏁版嵁搴1.dbo.琛1,鏁版嵁搴2.dbo.琛2锛屾暟鎹簱2.dbo.琛3
绛旓細瑙嗗浘涓病鏈鏁版嵁鐨勫師鍥犲緢绠鍗曪紝灏辨槸娌℃湁绗﹀悎瑙嗗浘鏉′欢鐨勬暟鎹晩锛sql server 涓嶄細楠椾汉鐨勶紒 妫鏌ヤ綘鐨勮鍥惧惂銆傚鏋滀綘涓嶆妸琛ㄧ粨鏋勫拰瑙嗗浘鍙戜笂鏉ワ紝璋佷篃甯笉鍒颁綘浜
绛旓細涓や釜鏁版嵁搴鍚嶅垎鍒负:data1鍜宒ata2,瀵瑰簲鐨勮〃渚濇鍒嗗埆涓:table1鍜宼able2銆傛垜鎯虫妸data1閲岀殑table1鐨勬暟鎹彃鍏ュ埌data2閲岀殑table2,鎬庝箞鍐SQL璇彞?鍙傝冭鍙:select*intodata2.table2in... 涓や釜鏁版嵁搴撳悕鍒嗗埆涓:data1 鍜 data2,瀵瑰簲鐨勮〃渚濇鍒嗗埆涓:table1鍜宼able2銆傛垜鎯虫妸data1閲岀殑table1鐨勬暟鎹彃鍏ュ埌data2閲岀殑tabl...