三张表 结构如下,
主表A
id pjid tasktypeid stateid
101 5 1 11
102 6 2 22
表B
pjid pjname
5 酒店台帐
6 超市台帐表 C
id keyvalue name note
tasktypeid 1 设计 任务类型
tasktypeid 2 编码 任务类型
stateid 11 未完成 任务状态
stateid 22 已完成 任务状态需要的查询结果 :
id pjid pjname tasktypeid name stateid name
101 5 酒店台帐 1 设计 1 未完成
102 6 超市台帐 2 编码 2 已完成
主表A
id pjid tasktypeid stateid
101 5 1 11
102 6 2 22
表B
pjid pjname
5 酒店台帐
6 超市台帐表 C
id keyvalue name note
tasktypeid 1 设计 任务类型
tasktypeid 2 编码 任务类型
stateid 11 未完成 任务状态
stateid 22 已完成 任务状态需要的查询结果 :
id pjid pjname tasktypeid name stateid name
101 5 酒店台帐 1 设计 1 未完成
102 6 超市台帐 2 编码 2 已完成
解决方案 »
- oracle10g升级后出现问题
- 报错,无效数字
- 复杂的求和问题!!!
- 共享我的ORACLE数据在LINUX下的远程备份解决方案!!
- 存储过程中动态sql中的一问题
- 一个查询语句?难
- 求救:如何优化oracle视图
- 求一查询的SQL语句
- 错误ORA-27101: shared memory realm does not exist,急急急。在线等。大侠们帮忙
- 刚装上oracle 9i如何用啊?用户名、口令是什么?
- proc insert 时出现ORA-01036: illegal variable name/number错误,查了一天了没发现错误。。。请各位帮忙看看
- count(*),count(1)和count(主键)的区别
select
t.id,t.pjid,t1.pjname,t.tasktypeid,t2.name tasktypename,t.stateid,t3.name statename
from A t
left join B t1 on t.pjid =t1.pjid
left join C t2 on t2.id='tasktypeid' and t.tasktypeid=t2.keyvalue
left join C t3 on t3.id='stateid' and t.stateid=t3.keyvalue
order by t.id,t.pjid,t.tasktypeid,t.stateid
select a.id,
a.pjid,
(select pjname from 表B b where a.pjid=b.pjid) as pjname,
a.tasktypeid,
(select name from 表C c where a.tasktypeid=c.keyvalue and c.id='tasktypeid') as tasktype_name,
a.stateid
(select name from 表C c where a.stateid=c.keyvalue and c.id='stateid') as state_name
from 主表A a
(select B.pjname from B where B.pjid = A.pjid) pjname,
A.tasktypeid,
(select C.name from C where c.id = 'tasktypeid'and C.keyvalue = A.tasktypeid) taskName,
A.stateid,
(select c.name from C where c.id = 'stateid 'and C.keyvalue = A.tasktypeid) stateName
from A
select a.*,b.*,c.* from a,b,(select * from c where note='任务类型') d,
(select * from c where note='任务状态') e
where a.pjid=b.pjid
and a.tasktypeid=d.keyvalue
and a.stateid=e.keyvalue
需要什么字段自己选择吧