sql >> Databasteknik >  >> RDS >> Mysql

Räkna besök idag, denna vecka, förra månaden och totalt [MySQL-fråga]

Ge dessa ett försök. Jag vet inte vad din tabell heter så jag har kallat den trafficTable :

-- Visits today
select count(*) as visits_today
from trafficTable tt
where tt.type != 'click'
and tt.id_user = '19d71'
and datetime >= curdate();

-- Visits this week
select count(*) as visits_this_week
from trafficTable tt
where tt.type != 'click'
and tt.id_user = '19d71'
and yearweek(datetime) = yearweek(curdate());

-- Visits this month
select count(*) as visits_this_month
from trafficTable tt
where tt.type != 'click'
and tt.id_user = '19d71'
and year(datetime) = year(curdate())
and month(datetime) = month(curdate());

-- Total visits
select count(*) as total_visits
from trafficTable tt
where tt.type != 'click'
and tt.id_user = '19d71';

--- if you want the last month - this help other ppl in other thread
    select count(*) as visits_this_month
    from trafficTable tt
    where tt.type != 'click'
    and tt.id_user = '19d71'
    and year(datetime) <= year(curdate())
    and month(datetime) <= month(curdate());


  1. K-Nearest Neighbor Query i PostGIS

  2. skapa dynamiska Div-taggar för AJAX-PHP-MySQL-genererad tabell

  3. HAS_DBACCESS() – Upptäck om en användare kan komma åt en databas i SQL Server

  4. Kan inte ansluta Azure Web App - NodeJS till Azure Mysql