php - How to get view for each article? -


i have 4 tables

articles category article_category view 

i need find view count each article below sql query

select a.id, (select sum(view) view v on v.aid=a.id) view  articles join article_category ac on a.id  on ac.aid join category c on c.id=ac.cid  left join view cv on v.aid=a.id group a.id 

my guestion if there ways without using select query?

it seems need take sum out of subquery , use it.

select a.id,sum(cv.view) articles  join article_category ac on a.id = ac.aid  join category c on c.id=ac.cid  left join view cv on v.aid=a.id group a.id 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -