Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rank not being determined properly

Tags:

sql

join

mysql

I'm using this query:

SELECT A.place_idx,A.place_id,B.TOTAL_CNT,(@r := @r + 1) AS rank FROM CUSTOM_LIST
AS A
INNER JOIN
(SELECT  @r := 0)
AS C
INNER JOIN
(SELECT place_id,COUNT(place_id) AS TOTAL_CNT from COUNT_TABLE GROUP BY place_id)
AS B ON B.place_id=A.place_id order by B.TOTAL_CNT desc;

Which gives this result:

1

But I want this result:

2

How do I need to modify my query? What am I doing wrong?

like image 464
KOREAN_DEVELOPER Avatar asked Sep 13 '12 15:09

KOREAN_DEVELOPER


People also ask

Why is my website not ranking well?

Your Website Has Been Penalized By Google This can consist of anything from building lots of spammy backlinks to your website t, to using over optimized anchor text or thin/duplicate content. Receiving a penalty will result in a loss of organic traffic and rankings making your website hard to find in search results.

Why are my articles not ranking?

In the vast majority of cases, a website not ranking in Google means that you need to invest in search engine optimization (SEO) — AKA the science of showing up in search when it matters most.


1 Answers

SELECT *,(@r := @r + 1) AS rank FROM 
(
  SELECT A.place_idx,A.place_id,B.TOTAL_CNT FROM CUSTOM_LIST
  AS A
  INNER JOIN
  (SELECT place_id,COUNT(place_id) AS TOTAL_CNT from COUNT_TABLE GROUP BY place_id)
  AS B ON B.place_id=A.place_id order by B.TOTAL_CNT desc
) AS T, (SELECT  @r := 0) AS tt
like image 142
PiTheNumber Avatar answered Oct 18 '22 22:10

PiTheNumber