خرید بک لینک

Vote count: 0

I have two tables (news, seen) and the relation between them is 1 to many: one news has many sees.

I need an SQL Query to get each news with an additional alias column valued by the sum of each news sees.

Here is the structure of the both tables:


News: id_news, news_title, news_text, date, time, pic

Seen: id_seen, id_user, id_news, ip, fulldate, time


I need a query that retus the result like:

id_news | news_title | news_text |  fulldate   | fulltime | pic   | seen_count (alias)
--------------------------------------------------------------------------------------
1       | Title Blah | Text Blah | Jun/03/2016 | 19:54:25 | 9.jpg | 934
2       | Title Blah | Text Blah | Jun/01/2016 | 19:24:25 | 6.jpg | 549


I tried lot of times but really couldn't achieve that.

asked 3 mins ago

1 Answer

Vote count: 0

select news.*, count(seen.id_seen) as seen_count from news 
left join seen on seen.id_news=news.id_news
group by news.id_news

answered 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 19 خرداد 1395 ساعت: 0:50

صفحه بندی