sql >> Database >  >> RDS >> Mysql

Tel bezoeken van vandaag, deze week, vorige maand en totaal [MySQL-query]

Geef deze een kans. Ik weet niet hoe je tabel heet, dus ik heb ernaar verwezen als 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. PL/pgSQL anoniem codeblok

  2. Invoegen in SQLite Database Android

  3. Hoe mySQL-informatie te splitsen om in HTML-kolommen te tonen

  4. INSERT INTO @TABLE EXEC @query met SQL Server 2000