New answers tagged

0

It sounds like wordmap is a many-to-many mapping table between articles (via article_id) and words via word_id? Please provide SHOW CREATE TABLE so we can verify. I suggest that that is "over-normalized". Instead, have CREATE TABLE wordmap ( article_id INT ..., word VARCHAR(77) ..., PRIMARY KEY(article_id, word), INDEX(word, ...


0

I answer this question because @ypercubeᵀᴹ was reluctant to do so, and I thought it might help others. The tricky part is to use COUNT(DISTINCT WordID) instead of COUNT(*), as the latter does not consider the repetition. As suggested by @ypercubeᵀᴹ, the ultimate solution is to use COUNT(DISTINCT WordID) and COUNT(*) together to have a perfect order ...


1

The most straightforward approach is to use a date table with all possible dates, then OUTER APPLY to get your hit count for each date, where appropriate. Something like this: SELECT d.Date ,ISNULL(hc.HitCount, 0) AS HitCount FROM dbo.Date AS d OUTER APPLY ( SELECT COUNT(1) AS HitCount FROM ...


Top 50 recent answers are included