[go: up one dir, main page]

Skip to content

devjiro76/SQL-popularArticle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

popularArticle

Sort popular articles with MySQL

Let's say

Let's say there is simple table which have columns as like below.

| id | title | crdate | read_cnt | voted_cnt |
----------------------------------------------
| 1  | hello | 2016.. | 34       | 12        |

Query

SELECT  id
        ,title
        ,crdate
        ,LOG10(ABS(read_cnt) + 1) / 2 * SIGN(read_cnt)
					  + LOG10(ABS(voted_cnt) + 1) * SIGN(voted_cnt) 
						+ (UNIX_TIMESTAMP(crdate) / 300000) as popular
FROM  articles
ORDER BY  popular DESC

About

Sort popular articles with MySQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published