根据不同的条件查询不同的表sql

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

/*
user_ID name
----------- --------------------------------------------------
1
a1
2
a2
user_ID name
----------- --------------------------------------------------
1
a1
2
b2
*/
select * from ta select * from tb select * from tc
--方法一
select c.[user_id],name=case user_type when 'a' then when 'b' then end from tc c,ta a,tb b where a.[user_id]=c.[user_id] and b.[user_id]=c.[user_id]
最新ip地址数据库全球旗舰版国内精华版智能dns掩码版号段归属地数据库行政区划省市区街道qqzengcom
/* a表 er_id b表 er_id c表 er_id er_type
根据不同的条件查询不同的表 sql
当c表的 er_type = "a" 时 它显示 a表的 当c表的 er_type = "b" 时 它显示 b表的 a,b,c表中的 er_id = er_id,er_id = er_id1b12 Nhomakorabeab2
user_ID user_type
----------- --------------------------------------------------
1
a
2
b
user_id 输出
----------- --------------------------------------------------
--方法二
SELECT FROM
er_ID, CASE user_type WHEN 'a' THEN WHEN 'b' THEN END AS 输出 tc INNER JOIN ta ON er_ID = er_ID INNER JOIN tb ON er_ID = er_ID
*/
if object_id('ta')is not null drop table ta
go create TABLE ta([user_ID] int,name varchar(50)) INSERT INTO ta select 1,'a1' union all select 2,'a2'
if object_id('tb')is not null drop table tb
go create TABLE tb([user_ID] int,name varchar(50)) INSERT INTO tb select 1,'b1' union all select 2,'b2'
if object_id('tc')is not null drop table tc
go create TABLE tc([user_ID] int,user_type varchar(50)) INSERT INTO tc select 1,'a' union all select 2,'b'
相关文档
最新文档