sql - Mysql - get results from complex criteria -


i have database statistics on number of websites , i'm having issue rather complex query have no idea how (or if it's possible).

i have 2 tables: websites , visits. former list of websites , properties, while former list of each user's visit on specific website.

the program i'm making supposed fetch websites need "scanned". interval between each scan each site depends on websites total number of visits last 30 days. here table intended scan-interval:

enter image description here

the tables have following structure:

websites enter image description here

visits enter image description here

what want query returns websites either at or past individual update deadline (can seen last_scanned column).

is doable in single query?

here's can try:

select main.*  (    select     w.web_id,     w.url,     w.last_scanned,     (select count(*)      visits v      v.web_id = w.web_id        , timestampdiff(day,v.added_on, now()) <=30     ) visit_count,     timestampdiff(hour,w.last_scanned, now()) hrs_since_update   websites w   ) main   (case      when visit_count >= 0 , visit_count <= 10 , hrs_since_update >= 4320 1     when visit_count >= 11 , visit_count <= 100 , hrs_since_update >= 2160 1     when visit_count >= 101 , visit_count <= 500 , hrs_since_update >= 1080 1     when visit_count >= 501 , visit_count <= 1000 , hrs_since_update >= 720 1     when visit_count >= 1001 , visit_count <= 2000 , hrs_since_update >= 360 1     when visit_count >= 2001 , visit_count <= 5000 , hrs_since_update >= 168 1     when visit_count >= 5001 , visit_count <= 10000 , hrs_since_update >= 72 1     when visit_count >= 10001 , hrs_since_update >= 24 1     else 0    end) = 1; 

here's fiddle demo: http://sqlfiddle.com/#!9/1f671/1


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -