在 t_book_issue 表添加了个downloadsum字段,t_content_delivery t     sum(t.download_count)可以统计下载次数update t_book_issue a set a.downloadsum  =
(
  select  downloadsum from 
          (select t_bi.id id,sum(t.download_count) downloadsum from t_content_delivery t,t_book_issue t_bi
           where t.file_content_id = t_bi.id 
           group by t_bi.id
          ) b

where a.id = b.id提升B  ID invalid identifier sql语句哪写的有问题,谢谢帮忙解决下

解决方案 »

  1.   

    ORA-00904:"B"."ID" :invalid identifier
      

  2.   

    where a.id = b.id这里的b.id不认的。
    建议改成
    where exists (  select 1 from  
      from t_content_delivery t 
     where t.file_content_id = a.id  
     )
      

  3.   


    update t_book_issue a set a.downloadsum =
    (
     select t_bi.id id,sum(t.download_count) downloadsum 
      from t_content_delivery t,t_book_issue t_bi
      where t.file_content_id = t_bi.id  
      group by t_bi.id
      ) b 
    where a.id = b.id
      

  4.   

    --错了
    update t_book_issue a set a.downloadsum =
    (
     select downloadsum
     from (
      select t_bi.id id,sum(t.download_count) downloadsum 
      from t_content_delivery t,t_book_issue t_bi
      where t.file_content_id = t_bi.id 
      group by t_bi.id
      ) b
      where a.id=b.id
    )
    where exists (select 1 from (
      select t_bi.id id,sum(t.download_count) downloadsum 
      from t_content_delivery t,t_book_issue t_bi
      where t.file_content_id = t_bi.id 
      group by t_bi.id
      ) b1 where b1.id=a.id)
      

  5.   


    set a.downloadsum =
    select t_bi.id id,sum(t.download_count) downloadsum set只有一个字段
    需嵌套
      

  6.   

    set的内容也不对。update t_book_issue a set a.downloadsum =
    (
      select sum(t.download_count) 
        from t_content_delivery t
      where t.file_content_id = a.id  
    )  
    where exists ( select 1 from   
      from t_content_delivery t  
     where t.file_content_id = a.id   
     )
      

  7.   


    掉了group by 
    分组了
      

  8.   

    set的select对t_book_issue where where t.file_content_id = t_bi.id 已经限定了。
    都是相同的t_bi.id ,还有必要对t_bi.id 进行分组吗?
      

  9.   

    子查询用了Group by 所以b.id 不能识别。
      

  10.   

    a.id = b.id
    为什么要放到外层呢?可以放到里边啊
      

  11.   

    update t_book_issue a set a.downloadsum =
    (
      select downloadsum from  
      (select t_bi.id id,sum(t.download_count) downloadsum from t_content_delivery t,t_book_issue t_bi
      where t.file_content_id = t_bi.id  
      group by t_bi.id
      ) b where a.id = b.id
    )
      
    where exists (select  1 from t_content_delivery t,t_book_issue t_bi
      where t.file_content_id = t_bi.id  and a.id =t_bi.id) 
      

  12.   


    update t_book_issue a set a.downloadsum = (select sum(t.download_count) downloadsum from t_content_delivery t
           where t.file_content_id = a.id 
           group by a.id
        )
    where a.id in (select file_content_id id from t_content_delivery)