how can i write as one query to get count in mysql

Mr world wide

enter image description here

I want to get the today count of users and yesterday's users count for that i want to write only one query how can i do that..?

these are my queries I want only one query:

SELECT COUNT(*) FROM visitors group by visited_date ORDER by visited_date DESC limit 1,1 as todayCount

SELECT COUNT(*) FROM visitors group by visited_date ORDER by visited_date DESC limit 1,0 as yesterdayCount

My expected results or only 2 columns

todayCount yesterdayCount
     2          4
Gordon Linoff

If you know the current and previous date, then you can do:

SELECT SUM(visited_date = CURDATE()) as today,
       SUM(visited_date = CURDATE() - interval 1 day) as yesterday
FROM visitors
WHERE visited_date >= CURDATE() - interval 1 day;

If you don't know the two days, then you can do something similar, getting the latest date in the data:

SELECT SUM(v.visited_date = m.max_vd) as today,
       SUM(v.visited_date < m.max_vd) as yesterday
FROM visitors v CROSS JOIN
     (SELECT MAX(v2.visited_date) as max_vd FROM visitors v2) as m
WHERE v.visited_date >= m.max_vd - interval 1 day

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I animate a MySQL query count?

From Dev

How can i write this query in MySql?

From Dev

How to write this MYSQL Query with count

From Dev

How to write this Mysql Query Count?

From Dev

How to get the COUNT of this mySQL query?

From Dev

How can I rewrite this MySQL query for returning a count?

From Dev

how can I estimate row count in mysql search query?

From Dev

How can i filter mysql query using count()?

From Dev

In MySQL how can I write this SQL query in the most efficient way?

From Dev

How Can i write update statement in mysql with select query?

From Dev

How can I count different mysql rows in one database request?

From Dev

How can I write this query

From Dev

How can I get value from one table and array of values from another join table in one mysql query?

From Dev

How can I get count of nulls per database on a MySQL server?

From Dev

MySql. How can i get count from 2 tables

From Dev

How can I get a count of times a value occurs by date in mysql

From Dev

How can I select from different tables in one MySQL query?

From Dev

How can I get both Folders and Documents with one Cmis query

From Dev

How can I get parent with all children in one query

From Dev

How to get data and count in one query in mongoose

From Dev

How to write a query with count

From Dev

How to write a query with count

From Dev

How can I get a history like query on MySQL?

From Dev

How can I update this MySQL query to get proper data?

From Dev

How to get the count from a filtered MYSQL query

From Dev

How to write a mysql query to get the desired data?

From Dev

How to write a query to get result in mysql

From Dev

How can I do this in one MySQL Select query, I want to lose the foreach loop and the second select query?

From Dev

How can I write a query with 2 states?

Related Related

  1. 1

    How can I animate a MySQL query count?

  2. 2

    How can i write this query in MySql?

  3. 3

    How to write this MYSQL Query with count

  4. 4

    How to write this Mysql Query Count?

  5. 5

    How to get the COUNT of this mySQL query?

  6. 6

    How can I rewrite this MySQL query for returning a count?

  7. 7

    how can I estimate row count in mysql search query?

  8. 8

    How can i filter mysql query using count()?

  9. 9

    In MySQL how can I write this SQL query in the most efficient way?

  10. 10

    How Can i write update statement in mysql with select query?

  11. 11

    How can I count different mysql rows in one database request?

  12. 12

    How can I write this query

  13. 13

    How can I get value from one table and array of values from another join table in one mysql query?

  14. 14

    How can I get count of nulls per database on a MySQL server?

  15. 15

    MySql. How can i get count from 2 tables

  16. 16

    How can I get a count of times a value occurs by date in mysql

  17. 17

    How can I select from different tables in one MySQL query?

  18. 18

    How can I get both Folders and Documents with one Cmis query

  19. 19

    How can I get parent with all children in one query

  20. 20

    How to get data and count in one query in mongoose

  21. 21

    How to write a query with count

  22. 22

    How to write a query with count

  23. 23

    How can I get a history like query on MySQL?

  24. 24

    How can I update this MySQL query to get proper data?

  25. 25

    How to get the count from a filtered MYSQL query

  26. 26

    How to write a mysql query to get the desired data?

  27. 27

    How to write a query to get result in mysql

  28. 28

    How can I do this in one MySQL Select query, I want to lose the foreach loop and the second select query?

  29. 29

    How can I write a query with 2 states?

HotTag

Archive