logo
down
shadow

mysql Group by today


mysql Group by today

By : Hampus Siroky
Date : October 21 2020, 08:10 AM
This might help you You may try rechnung.datum = curdate() in WHERE clause rather GROUP BY since you only need records of today.
code :
  SELECT rechnung.*, re_kunden.*,  SUM(re_kunden.gpreis) as preise 
  FROM rechnung
     LEFT JOIN re_kunden ON rechnung.ID = re_kunden.ID_rechnung
     WHERE rechnung.ID LIKE re_kunden.ID_rechnung
     AND rechnung.datum = curdate()


Share : facebook icon twitter icon
Get data from db relevant with today, yesterday, today -1.week, today -1.month

Get data from db relevant with today, yesterday, today -1.week, today -1.month


By : ejvk
Date : March 29 2020, 07:55 AM
I wish this help you Depending on how you want to later use the results, it might make sense to query them individually using your second approach. That way, you don't have to further separate them in your resultset.
If you don't actually need the data you query in your first approach, it doesn't make sense to retrieve them from the database. You should then use another, more specific approach.
code :
dates = [
  Date.today,
  Date.today - 1.day,
  Date.today - 1.week,
  Date.today - 1.month
]

resultset = Result.where('DATE(created_at) IN (?)', dates)
SELECT * from results WHERE DATE(created_at) IN ('2013-12-16', '2013-12-15', '2013-12-09', '2013-11-16');
how to group mysql based on items and today date

how to group mysql based on items and today date


By : Patrick Maloney
Date : March 29 2020, 07:55 AM
it fixes the issue I have a database that store transaction logs, I would like to count all the logs for that day and group them based on prod_id , Use DISTINCT with COUNT on PROD_ID.
Example:
code :
SELECT count( distinct PROD_ID ) as count 
 FROM PRODUCTS 
 WHERE PERSON = 1  -- <---- change this with relevant variable
   AND DATE( FROM_UNIXTIME (DATE ) ) = curdate();
How to group data in MySQL for every 3 hours from today?

How to group data in MySQL for every 3 hours from today?


By : user2315291
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I would like to retrieve data for one of my charts and I'd like to come up with a simple solution for it, instead of doing 8 subqueries. , You can just use aggregation and arithmetic on the hour:
code :
select floor(hour(time) / 3) as hourgroup, sum(points)
from pts
where status = 0 and user_id = 1 and
      date(time) = "THIS DAY"
group by floor(hour(time) / 3);
select (hour(time) div 3) as id, user_id, sum(points),
       date('2014-08-23') + interval 3 * (hour(time) div 3) hour as starttime,
       date('2014-08-23') + interval 3 * ((hour(time) div 3) + 1) hour as endtime
from pts
where status = 0 and user_id = 1 and
      date(time) = date('2014-08-23')
group by floor(hour(time) / 3);
select n.n as id, user_id, sum(points),
       date('2014-08-23') + interval 3 * n.n hour as starttime,
       date('2014-08-23') + interval 3 * (n.n + 1) hour as endtime
from (select 0 as n union all select 1 union all select 2 union all select 3 union all
      select 4 union all select 5 union all select 6 union all select 7
     ) n left join
     pts
     on n.n = hour(time) div 3
where status = 0 and user_id = 1 and
      date(time) = date('2014-08-23')
group by n.n;
Updating mysql database table, set date column of anything earlier than today with today's date

Updating mysql database table, set date column of anything earlier than today with today's date


By : Gabriel Oliveira
Date : March 29 2020, 07:55 AM
Hope that helps For MySql:
Update dealers set next_call_date = now() where date(next_call_date)
MySQL Sort by Date Where Date >= Today first in ascending, then Date < Today in descending in 1 Query

MySQL Sort by Date Where Date >= Today first in ascending, then Date < Today in descending in 1 Query


By : Luky
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Actually, there isn't actually anything wrong with your technique it's purely that your first case when doesn't output anything when the date is less than the 14th so it outputs NULL, and null ranks lower than a value so they all sort towards the start when the date is less than the 14th:
code :
SELECT *
FROM `activity`
ORDER BY
    CASE WHEN `activity_date` >= '2019-06-14' THEN `activity_date` ELSE '2999-01-01' END ASC,
    CASE WHEN `activity_date` < '2019-06-14' THEN `activity_date` END DESC
SELECT *
FROM `activity`
ORDER BY
    CASE WHEN `activity_date` >= '2019-06-14' THEN 0 ELSE 1 END,
    CASE WHEN `activity_date` >= '2019-06-14' THEN `activity_date` END ASC,
    CASE WHEN `activity_date` < '2019-06-14' THEN `activity_date` END DESC
2019-06-14 --sorted by 0, then date
2019-06-15 --sorted by 0, then date
2019-06-16 --sorted by 0, then date
2019-06-13 --sorted by 1, then date
2019-06-12 --sorted by 1, then date
2019-06-11 --sorted by 1, then date
SELECT *
FROM `activity`
ORDER BY
    CASE 
      WHEN activityrating = 'gold' THEN -1 
      WHEN `activity_date` >= '2019-06-14' THEN 0 
      ELSE 1 
    END,
...
Related Posts Related Posts :
  • How to setup local server for wordpress site with git
  • Multiplying CASE row with different values
  • Index on a table not being used all the time
  • How can I get a date from mysql database if it is not null?
  • How to execute a TRIGGER in MSSQl?
  • MySQL 8 Window Functions + Full-text searching
  • Join on large table getting slower
  • Select record from two different table
  • Getting 1064 error while creating mysql trigger
  • MySQL Database Operations
  • How can I make this SQL sort by most relevent?
  • Database query on month
  • Select number of matching rows of a particular column in MySQL
  • How to use rake database commands with password
  • If we change a primary key value, why don't we have to change a dependent column value?
  • MySQL - selecting all records except the ones already associated in the relational table
  • Delete Duplicate MySQL rows but keep one
  • ORDER BY does not perform any function
  • Update column with output of select within the same table in mysql
  • Set a variable inside case statement in mysql
  • MYSQL: How to get rows inserted in the last X hours without querying the entire table
  • AWS RDS MySQL Cross-region replication
  • Cannot truncate a table referenced in a foreign key constraint from empty table
  • How does SQL determine a character's length in a varchar?
  • MySQL : Getting DB row with exact same data from a vector
  • Mysql update query with join
  • Group values that have the same name in one column and same id in other column
  • Mysql query syntax for conditional inserts
  • Is it faster to run an SQL count(*) query in a loop, or try to merge it into the parent query?
  • MySQL query to fetch product variants
  • Report Reindex taking too long after destroy
  • MySQL - Adding varchar as a foreign key
  • How to find duplicated entries which has different slug?
  • SQL Query comparing values in different rows
  • Eloquent giving error but query executes fine in phpmyadmin
  • JPQL fetch data from multiple tables
  • MySql Query - Expanding data into new table
  • Official MySQL Docker container not caching queries?
  • MySQL, Count values in every fields in a table
  • SQL : number different dates within users
  • elastic beanstalk docker app cannot connect to mysql
  • Why am I getting errno: 150 "Foreign key constraint is incorrectly formed"?
  • Update columns which included in payload
  • MySQL subquery in select
  • Get difference in top 2 salary of employee from each department
  • connecting to database using RMySQL and .my.cnf file in R
  • How to get data by mysql
  • SQL Error [1054] [42S22]: Unknown column ' ' in 'field list'
  • turn c# code into mysql function
  • How to loop through and output nested array in Laravel
  • MySQL TRIM spaces inside text
  • Mysql query with multiple selects results in high CPU load
  • Backup DB Django MysqlDump
  • How to select all rows from group, until occurrence of a value
  • Using substring to filter a specific word from a string in MySQL
  • Mysql - Alias in Left Outer Join giving error
  • How use custom alias field from select fields in join?
  • How to sum durations in units of Year, Month and Day in MySQL?
  • Is it possible to assign the values from select exist query in MySQL to multiple variables in a stored procedure?
  • How does mysql resolves conflict when same option is configured twice?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org