几张表,简单起见,贴两张表的图,其他表同理。check_log表:
NewsDoc表:
想要实现这样一个功能:
1.如果 check_log.table_name字段的内容是NewsDoc,则执行:
select *
from check_log, NewsDoc
where check_log.table_name.news_id = NewsDoc.ID2.如果check_log.table_name字段的内容是Orgnization0,则执行:
select *
from check_log, Orgnization0
where check_log.table_name.news_id = Orgnization0.ID3.如果check_log.table_name字段的内容是InvestDoc,则执行:
select *
from check_log, InvestDoc
where check_log.table_name.news_id = InvestDoc.ID不知道表达清楚了没有,请大家给看看,这样一个查询能不能在一个sql语句中写出来请教,多谢!
NewsDoc表:
想要实现这样一个功能:
1.如果 check_log.table_name字段的内容是NewsDoc,则执行:
select *
from check_log, NewsDoc
where check_log.table_name.news_id = NewsDoc.ID2.如果check_log.table_name字段的内容是Orgnization0,则执行:
select *
from check_log, Orgnization0
where check_log.table_name.news_id = Orgnization0.ID3.如果check_log.table_name字段的内容是InvestDoc,则执行:
select *
from check_log, InvestDoc
where check_log.table_name.news_id = InvestDoc.ID不知道表达清楚了没有,请大家给看看,这样一个查询能不能在一个sql语句中写出来请教,多谢!
解决方案 »
- 我之前看到一个条sql语句,说是2005新增的函数
- 怎么能看出SQLserver 是不是企业版的。
- sql 2005 float字段出现 非数字 字段内容
- 请问用友U8当中应收应付结算单存放在哪个表呀?
- 网站总是有人访问,想进入单用户模式怎么办?
- [求助]数据库容量太大导致无法查询的问题
- 如何这样的存储过程,并能自动执行
- 为何老出现“超时已过期”字样....
- zqllyh(您问我也问总可以问出个所以然),pengdali(大力)和j9988(j9988) 请进,这900分特别酬谢《
- exec master..xp_cmdshell 'dtsrun ..'产生错误。存储过程怎么调用DTS?
- 请帮我看看错出在哪里!
- windows7下能安装,mysql吗?
不过我感觉应该是3个left join
看不清你的图片
from check_log, NewsDoc
where check_log.table_name.news_id = NewsDoc.ID and check_log.table_name = 'NewsDoc'
union all
select *
from check_log, Orgnization0
where check_log.table_name.news_id = Orgnization0.ID and check_log.table_name = 'Orgnization0'
union all
select *
from check_log, InvestDoc
where check_log.table_name.news_id = InvestDoc.ID and check_log.table_name = 'InvestDoc'
from check_log, NewsDoc
where check_log.table_name.news_id = NewsDoc.ID and check_log.table_name = 'NewsDoc'
union all
select *
from check_log, Orgnization0
where check_log.table_name.news_id = Orgnization0.ID and check_log.table_name = 'Orgnization0'
union all
select *
from check_log, InvestDoc
where check_log.table_name.news_id = InvestDoc.ID and check_log.table_name = 'InvestDoc'如果上述不行,就自己更改字段名,类型,顺序,数量都相同,至少如下是行得。
select check_log.*
from check_log, NewsDoc
where check_log.table_name.news_id = NewsDoc.ID and check_log.table_name = 'NewsDoc'
union all
select check_log.*
from check_log, Orgnization0
where check_log.table_name.news_id = Orgnization0.ID and check_log.table_name = 'Orgnization0'
union all
select check_log.*
from check_log, InvestDoc
where check_log.table_name.news_id = InvestDoc.ID and check_log.table_name = 'InvestDoc'
那就一个一个写.如果字段名,类型,顺序,数量都相同,则用union allselect *
from check_log, NewsDoc
where check_log.table_name.news_id = NewsDoc.ID and check_log.table_name = 'NewsDoc'
union all
select *
from check_log, Orgnization0
where check_log.table_name.news_id = Orgnization0.ID and check_log.table_name = 'Orgnization0'
union all
select *
from check_log, InvestDoc
where check_log.table_name.news_id = InvestDoc.ID and check_log.table_name = 'InvestDoc'如果上述不行,就自己更改字段名,类型,顺序,数量都相同,至少如下是行得。
select check_log.*
from check_log, NewsDoc
where check_log.table_name.news_id = NewsDoc.ID and check_log.table_name = 'NewsDoc'
union all
select check_log.*
from check_log, Orgnization0
where check_log.table_name.news_id = Orgnization0.ID and check_log.table_name = 'Orgnization0'
union all
select check_log.*
from check_log, InvestDoc
where check_log.table_name.news_id = InvestDoc.ID and check_log.table_name = 'InvestDoc'
你自己多写了一个,我也没仔细看.应该如下:如果上述不行,就自己更改字段名,类型,顺序,数量都相同,至少如下是行得。
select check_log.*
from check_log, NewsDoc
where check_log.news_id = NewsDoc.ID and check_log.table_name = 'NewsDoc'
union all
select check_log.*
from check_log, Orgnization0
where check_log.news_id = Orgnization0.ID and check_log.table_name = 'Orgnization0'
union all
select check_log.*
from check_log, InvestDoc
where check_log.news_id = InvestDoc.ID and check_log.table_name = 'InvestDoc'