logo
down
shadow

MySQL Distinct Active Users for the last month query


MySQL Distinct Active Users for the last month query

By : user2955387
Date : November 22 2020, 10:40 AM
should help you out Seems like your sql is incorrect, try replacing the single quotation marks around 'uid' with `.
code :
SELECT COUNT( DISTINCT `uid` ) AS `Records` , DATE( FROM_UNIXTIME( `epoch_timestamp` ) ) AS `Date`
FROM `log`
GROUP BY DATE( FROM_UNIXTIME( `epoch_timestamp` ) )
LIMIT 0 , 30


Share : facebook icon twitter icon
mysql - how to get number of unique active users per month who posted or commented?

mysql - how to get number of unique active users per month who posted or commented?


By : madoka
Date : March 29 2020, 07:55 AM
seems to work fine I have the following tables:
code :
SELECT
  T.action_year,
  T.action_month,
  COUNT(T.user_id) active_users
FROM
  (
  SELECT DISTINCT user_id, YEAR(post_date) action_year, MONTH(post_date) action_month FROM content
  UNION
  SELECT DISTINCT user_id, YEAR(comment_date) action_year, MONTH(comment_date) action_date FROM comment
  ) T
GROUP BY
  T.action_year,
  T.action_month
ORDER BY
  T.action_year ASC,
  T.action_month ASC
MYSQL query count + distinct for current month

MYSQL query count + distinct for current month


By : Nate D
Date : March 29 2020, 07:55 AM
this will help You probably need to include the year in the where clause as well as the month. Then you need a GROUP BY and the right logic:
code :
SELECT username, COUNT(recid)
FROM transactions
WHERE YEAR(CURDATE()) = YEAR(update_timestamp) AND
      MONTH(CURDATE()) = MONTH(update_timestamp)
GROUP BY username
ORDER BY COUNT(recid) DESC
LIMIT 5;
SELECT username, COUNT(recid)
FROM transactions
WHERE update_timestamp >= date_sub(CURDATE(),  interval day(CURDATE()) - 1 day) AND
      update_timestamp < date_add(date_sub(CURDATE(),  interval day(CURDATE()) - 1 day), interval 1 month)
GROUP BY username
ORDER BY COUNT(recid) DESC
LIMIT 5;
MySql query Script to count active users in every month

MySql query Script to count active users in every month


By : Elkana Mutuma
Date : March 29 2020, 07:55 AM
like below fixes the issue You can do this with a trick. Add one month from each date and then you can use union all and aggregation for the count:
code :
select year(logindate), month(logindate), count(distinct userid)
from ((select logindate, userid
       from logger
      ) union all
      (select date_add(longdate, interval 1 month), userid
       from logger
      )
     ) l
group by year(logindate), month(logindate)
order by 1, 2;
select year(l.logindate), month(l.logindate), count(distinct l.userid)
from logger l
where exists (select 1
              from logger l2
              where l2.userid = l.userid and
                    year(date_sub(l.logindate, interval 1 month)) = year(l2.logindate) and
                    month(date_sub(l.logindate, interval 1 month)) = month(l2.logindate)
             )
group by year(l.logindate), month(l.logindate);
MySQL - count active/inactive/banned users and sellect users based on status in one query

MySQL - count active/inactive/banned users and sellect users based on status in one query


By : Guk-Hui Shin
Date : March 29 2020, 07:55 AM
help you fix your problem There is no way to get your expected output with one single query (since the strcuture of the result is different). You have to use two different querys to get the expected information of the users table:
1 - You can get the status overview with the following:
code :
SELECT 
  SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END) AS active_users,
  SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) AS inactive_users,
  SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) AS banned_users
FROM users
SELECT *
FROM users
WHERE status = 0
MYSQL query select distinct month and year

MYSQL query select distinct month and year


By : user1172773
Date : March 29 2020, 07:55 AM
Any of those help I have a table with a datetime column with multiple dates in. I want to output the month and year for every row that exists only once. e.g "April 2017, April 2018, May 2018, June 2018" , You can apply the distinct keyword to a combination of fields:
code :
SELECT DISTINCT YEAR(date_added) AS "Year", MONTH(date_added) AS "Month" FROM payments
Related Posts Related Posts :
  • MySQL join optimization - bypassing filesort
  • How to Select record with the maximum value in a GROUP BY?
  • MySQL Innodb Full text Proximity Search Gives Horrible Performance
  • MySQL best approach for db normalising, relationships and foreign keys
  • How to update one table based on the count value of another table while matching ids?
  • MAMP Pro 5.1.1-terminates MySQL when quitting
  • SQL - Get date of most votes cast
  • "Fuzzier" search in mysql
  • Tracing mysqld Using SystemTap
  • SELECT + INSERT + Query Cache = MySQL lock up
  • SQL vs. NoSQL for medium complexity search systems
  • SQL Error when creating table
  • Is it possible to write a query to compare rows to other rows in same table?
  • Display all duplicate records based multiple columns
  • summing time column in mysql
  • InnoDB: Cannot open table
  • Why is IN() considered O(logN) operation?
  • Can a deadlock occur on commit?
  • Is there a fast way to do a '%phrase%' search in any DB?
  • Is using an IN over a huge data set a good idea?
  • How can I know if a table is already arranged in ascending order in MySQL?
  • MySQL - Designing database for a simple game
  • Why am I getting "Host '192.168.1.220' is not allowed to connect to this MySQL server"?
  • what type of password hash? possible mysql hash?
  • MySQL - Using a date range vs functions
  • Using IS NULL and COALESCE in OrderBy Doctrine Querybuilder
  • How to merge MySQL columns into one column if there are empty values in the table?
  • Cardinality Confusion
  • Renaming column multiple ids in SELECT
  • Group all from and to messages per user
  • How to handled the null values in WHERE IN condition in mysql
  • Is it okay to update primary key field to shift a record to the top?
  • Stop query through pdo
  • How to check whether particular value in field in MySQL exists
  • Execute a statement for every table in a database
  • insertion 74G data into mysql table cost more then 2 days, how to improve insert performance
  • Where can I see the differents "Hibernate Console Configurations" in Eclipse
  • MySql | relational database vs non relational database in terms of Performance
  • Exporting mysql database using mysqldump including procedures
  • Trigger MySQL not working
  • How do I update values for individual rows quickly?
  • MySQL join query with multiple where condition
  • MySQL stored procedure is not working
  • MySQL - Order By exact match at the end
  • Select max date or null date from same table MySQL
  • Best solution workaround for needing a mysql event on insert?
  • MySQL select several columns of several tables at the same time without using JOIN
  • Is it more efficient to have a table with one of its columns mostly empty or make a new table and refer to it?
  • mysql data truncated with ñ character
  • Get all rows that match another attribute in the same table
  • MySQL statement to get min value with max ID
  • DATEDIFF Current/Date for Last Record
  • What is the logic or procedure for combining multiple DB query's results into one elegant table?
  • Modify TIMESTAMP MySQL for use as Primary Key
  • Django - Efficiently bulk create inherited models
  • MySQL Dual table Join Dual table
  • Ruby on Rails - database where sorted by id
  • MySQL 5.6 : Access denied for user 'root' @ 'localhost' when password contains backslash
  • sql query case dateadd
  • Click on one button multiple times and mySql
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org