Is it possible to run MySQL event based on dates stored in table?
For example if I have table like
| id | date |
|----|------------|
| 1 | 2016-05-20 |
| 2 | 2016-05-25 |
| 3 | 2016-06-15 |
...
can I run event automatically at 2016-05-20, 2016-05-25 and 2016-06-15?
Your daily event should check that table and run its code if today's date is in it !
Yes, It's possible to run event automatically at 2016-05-20, 2016-05-25 and 2016-06-15 dates by using cron-job.
You can run daily event, check with your table date and run its code.
Suppose you want to automatically run your script file at some dates, you need to set cron-job using php. Ref How to create cron job using PHP
Related
I have a MariaDB database holding some data for a game and I wanted to use Grafana to graph out how many rows have been inserted every minute. I'm using a Node.js script to fetch the data every minute from the game's Public API and insert it into my db, however I can't figure out how to get MySQL to output something that works with Grafana. What I need it to do is output a table with a column for the number of new inserts and the time at the start of the one minute window. My DB looks something like this:
--------------------------------------------------------------------
| auction_id | seller | buyer | timestamp | price | bin | item_bytes |
--------------------------------------------------------------------
I have a working query for returning the number of new inserts for the current data supplied by the API, however I can't figure out how to get the historical data for the past minutes. The output I'm looking for would look something like this:
-----------------------------
| new inserts | timestamp |
-----------------------------
| 234 | 1625373706053 |
-----------------------------
| 684 | 1625373666053 |
-----------------------------
| 720 | 1625373626053 |
-----------------------------
| 403 | 1625373586053 |
-----------------------------
Notice how the timestamp goes down by 60,000 every row, which is equivalent to 60 seconds, or a minute. I have tried using GROUP BY and almost every other solution I could find on StackOverflow and other sites, however it still doesn't work.
Please don't hesitate to comment if I wasn't clear enough.
You may use UNIX_TIMESTAMP to convert your milliseconds-since-epoch values into a bona fide datetime. Then, aggregate by minute to get the counts:
SELECT
COUNT(*) AS `new inserts`,
FROM_UNIXTIME(timestamp / 1000, '%Y-%m-%d %H:%i') AS ts_minute
FROM yourTable
GROUP BY ts_minute
ORDER BY ts_minute;
I am looking to create a booking system. On one end you have a client looking to book an appointment and on the other end you have a provider who has a schedule that a client can book against
When signing up as a provider they are allowed to pick their days of work and hours. They have html check-boxes which represent which days they can select and once they select a day the hours are are displayed (drop-downs in angular) as you can see below
html schedule form
On the MySQL side I am thinking I can have a table which has a column for each day and have a comma separated list in there for the start time, end time, lunch time and lunch length
i.e. Provider selects Monday and Tuesday to work from the hours below
Provider 'Schedule' Table
|ScheduleID|ProviderID|Monday |Tuesday |Wednesday|Thursday|Friday|Saturday|Sunday|
|----------|----------|--------|--------|---------|--------|------|--------|------|
|1 | 2 |09:00am,|10:00am,| | | | | |
| | |08:30pm,|07:00pm,| | | | | |
| | |12:00pm,|01:00pm,| | | | | |
| | |30 min |60 min | | | | | |
|----------|----------|--------|--------|---------|--------|------|--------|------|
The table would have a schedule id and a provider id which links back to the "provider" table to link the provider to his schedule
Or is this better?
|-------------|-------------|----------|-----------|----------|------------|--------------|
| schedule_id | provider_id | week_day |start_time | end_time | lunch_time | lunch_length |
|-------------|-------------|----------|-----------|----------|------------|--------------|
| 1 | 1 | Monday | 06:00 AM | 08:00 PM | 12:30 PM | 60 |
|-------------|-------------|----------|-----------|----------|------------|--------------|
| 2 | 1 | Friday | 06:00 AM | 08:00 PM | 12:30 PM | 60 |
|-------------|-------------|----------|-----------|----------|------------|--------------|
| 3 | 2 | Tuesday | 06:00 AM | 08:00 PM | 12:30 PM | 60 |
|-------------|-------------|----------|-----------|----------|------------|--------------|
if not post something that is
Before I go into how I believe you should structure your Provider 'Schedule' Table, please make sure to, in the future, remove fluff.
More on fluff here.
It may serve you better to make the following changes:
make all column headers lowercase, as this might prevent errors if you attempt to query your database another way
change scheduleId to id
Instead of having seven columns, one for every day of the week, you could simply put a weekDay column that stores the value of that weekday
Then create columns for startTime, endTime, lunchTime and lunchLength
Finally, create a scheduleId column that ties together all the different weekday rows of someone's schedule to one provider
Some considerations:
Instead of having strings "Monday" or "Sunday" in the weekDay column you could instead insert 0..6, where 0 is a Sunday and 6 is a Saturday to make it more compatible with other languages
You could always just keep scheduleId in this table and create another table with the individual schedule days and link them with a foreign key, but this might prove to cause more problems than it's worth
Keeping that lunchLength as just an integer, as that will make everything easier
The reasoning behind splitting up the data as much as possible is because if you are querying using another language you might need to go through all the extra work of splitting those Monday and Tuesday columns if you just want the startTime for instance.
Hopefully the above is either a solution or allows you to consider another approach.
Here is a Java Android Library that you can convert into JavaScript: https://bitbucket.org/warwick/schedule_utils_demo/src/master/
Running the code in a client side language will save your server the burden as scheduling code is very inefficient.
Hope this helps.
This is what I want to do...
1. read table
2. if UPDATE_REQ is not equal to 0000-00-00 00:00:00 or NULL
then
do move data from infonew to infomain
do delete data from infonew
do reset value of update_req to null
3. else end script
TABLE looks like this...
shopname | infomain | infonew | date
ABC | Location | New location | 2014-01-01 10:00:00
XYZ | Location | Null | 0000-00-00 00:00:00
Please help me which is the best solution (Create a trigger in phpmyadmin, create bash script or create php script)
Thanks! I am looking forward to your response.
I have a database schema like this:
sms_queue
---------------
id
status
Date Time
How do I arrange codeigniter active record to update the status only for the passed day (date time) the reference time is the time when I call the function?
Let say according to my time zone, it is on 11-01-14 (11th january 2014), and i have 5 tuple.
sms_queue
+----+--------+----------------+
| id | status | Date Time |
+====+========+================+
| 1 | unsent | 15-01-14 18:45 |
| 2 | unsent | 02-01-14 08:15 |
| 3 | unsent | 01-01-14 07:00 |
| 4 | unsent | 11-01-14 09:00 |
| 5 | unsent | 13-01-14 07:00 |
+----+--------+----------------+
what where clause on active record / sql statement should i use to select only for the second and third data above assuming today is 11-01-14
i mean the query must be like this
$this->db->where(blablabla)
->update('sms_queue',array('status'=>'sent'))
so what is the blablabla
i hope the answer is using active record not a sql statement since it says that using codeigniter active record is more safer for security issue.
Finally i could answer my own question and found the solution for my specific problem.
i use this one
$this->db->where('Date time <',date(Y-m-d))
->update('sms_queue',array('status'=>'sent'));
The query will update the status to be sent for every item who have the date time on the past day of today.
Sorry if my question is not so clear. Sorry for my bad english.
I'm very new to Grails. I have a table like this :
+----+---------+----------------+----------------+-------------+--------------------+--------------+--------+---------------------+
| id | version | card_exp_month | card_exp_year | card_number | card_security_code | name_on_card | txn_id | date_created |
+----+---------+----------------+----------------+-------------+--------------------+--------------+--------+---------------------+
| 9 | 0 | ASdsadsd | Asdsadsadasdas | Asdsa | | batman | asd | 2012-08-13 19:38:22 |
+----+---------+----------------+----------------+-------------+--------------------+--------------+--------+---------------------+
In mysql. I wish to run a Quartz job against this table, which will compare, date_created Time stamp with present time such that, if any field's there with timestamp less than 30 minutes should be deleted.
How can I do this?
you could define a Job implementing your logic ( in the execute() method, check (date_created - now) < 30 minutes or else delete the row in the database) and then trigger this job on a regular basis.
You can read the documentation http://quartz-scheduler.org/documentation/quartz-2.1.x/cookbook or have a look at the examples : http://svn.terracotta.org/svn/quartz/branches/quartz-2.2.x/examples/src/main/java/org/quartz/examples/example1/
Check this example for grails quartz:
http://www.juancarlosfernandez.net/2012/02/como-crear-un-proceso-quartz-en-grails.html