日期:2014-05-17  浏览次数:20925 次

请教高手们一个oracle问题.
select   sj_id   from   tb_subject   where   sj_name= '文史 '

select   count(*)   num   from   tb_content   where   sj_id   =   '25695 '

这2个sql语句.我要合成一个.

select   count(*)   num   from   tb_content   where   sj_id   =(select   sj_id   from   tb_subject   where   sj_name= '文史 ')

这样老报一个无效数字.于是我又写成这样.

select   count(*)   num   from   tb_content   where   sj_id   = ' '(select   sj_id   from   tb_subject   where   sj_name= '文史 ') ' '

但是也不对,请问遇到这样问题怎么办啊?我刚开始接触oracle,有些写法确实不知道.请指教.

------解决方案--------------------
你要实现什么功能呢?
------解决方案--------------------
select count(*) num from tb_content where to_char(sj_id) =(select to_char(sj_id) from tb_subject where sj_name= '文史 ')
不知道tb_content中的sj_id的类型与tb_subject中的sj_id类型是否相同
------解决方案--------------------
估计类型应该相同,有可能第一个查询中会查询到复数件数的数据出来吧
------解决方案--------------------
Top
dlxu(脱离纯粹Coding阶段) ( ) 信誉:100 Blog 加为好友 2007-6-26 9:05:31 得分: 0



估计类型应该相同,有可能第一个查询中会查询到复数件数的数据出来吧