在 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语句哪写的有问题,谢谢帮忙解决下
(
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语句哪写的有问题,谢谢帮忙解决下
建议改成
where exists ( select 1 from
from t_content_delivery t
where t.file_content_id = a.id
)
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
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)
set a.downloadsum =
select t_bi.id id,sum(t.download_count) downloadsum set只有一个字段
需嵌套
(
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
)
掉了group by
分组了
都是相同的t_bi.id ,还有必要对t_bi.id 进行分组吗?
为什么要放到外层呢?可以放到里边啊
(
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)
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)