Is there a way to know the number of records added into the SQL database after a particular date and time - mysql

The table doesn't have any date time column. I want to if there is any inbuilt keyword which can does that.
I want to know all commits done after a particular date.

If flashback is enabled on the database you can get records on the table in an around a particular date range in Oracle.(It purely depends on if its enabled and for how long the flashback needs to be kept)
You can query to see the data in the table as of 3 days back as follows
select *
from table as of timestamp sysdate-3

Related

Updating mysql table whilst shifting values

I have a table that I use for statistical purposes.
Its columns are id and 1,2,3,..,31 and pivot.
This table gives the number of views on each day for the last 31 days.
1 gives the number of views for yesterday.
14 gives the number of views for 14 days ago.
etc ...
(pivot is just used to calculate the number of views)
I would use a cron job every day to update this table, but how would I go about "shifting" all the values to the side ( value column 15 would become value column 16; new value for column 1; delete value for column 31)
Define a table with only two columns — "date" and "views"
INSERT a new row in the table with the view count for that day when the CRON job runs
Modify your application query to read through this new table over a custom date range, which could be 31 days or anything else either — please have a look at this link to get an idea:
MySQL Query - Records between Today and Last 30 Days
Not really sure how pivot is being used here. However, I'm almost certain that if you're using it to store the sum of the views, it could as well be computed by using SUM() or GROUP BY without having to need a separate column in the table
As far as data archival / removal is concerned, your daily CRON job could be modified to include a DELETE query (as the last step) which cleans up records older than a certain date. Again, you could use the link above to get your "target" date
.
I apologise that this might sound like a little too long a solution to what you've asked for. However, I feel, this approach should help you organise and maintain the table in question in a better way.

I want a basic syntax to create a time dimension table in MYSQL

I want to create a time dimension table so that I can have data inserted for example for every minute of a certain day or every hour of a certain day. I have already made a date dimension table so I hope I can eventually reference my time dimesnion table with my date dimension table to for example select data for a specific time on a specific day throughout the year.
Thanks
Just have column with a timestamp datatype in your table
whenever you insert data into the table have a function now() to inset data inplace of timstamp column
when you want to select the data in a particular timeframe and in particular data use between
use other date functions to get the data you desire
Not getting your question fully but hope cron job will help you.

Sorting by time not working truly in MySql

I think title is clear what is my problem. I am working with MySql I just wanted to know what was the first registration on my website and when I sorted the table according to timestamp, the id of people who registered on the website were not true. The Image bellow will show what do I mean:
and this is the code what phpMyAdmin created:
SELECT *
FROM `table`
ORDER BY `table`.`timestamp` ASC
LIMIT 0 , 30
whats wrong with my table time? and why id is not ordered same as timestamps
If we assume that id is an auto-increment field, then this is almost certainly due to the fact that timestamp column is not assigned at the same physical time the id column is assigned. For example, if you have a multi-page registration from a website application, the initial object may be inserted into the database to contain the initial data fields gathered on the first page. But perhaps the timestamp is only set after the final page of registration is complete. So depending on the time the user takes to complete registration, the timestamp can be out-of-sync with the id order.
There are multiple ways to work around this. One way is to assign timestamp when the record is first inserted into the database, or you could use a DB insert trigger to populate the timestamp field instead.
There is also the possibility that timestamp represents the date and time the user last modified their profile (or otherwise caused modification of the database record). In this case, the timestamp could be changing to a "future" value while the id stays constant.

sql query count daily difference / count new rows, no date column

I have a database for our local real estate listings, there are no dates or timestamp columns.
I would like to be able to get out just the rows that were added in the past day or two.
Can anyone point me in the right direction to get this data out?
EDIT:
Each new row does get a new id number which is incrementally higher, so I can ORDER the results by newest.
Would it be possible to save my query count in a file, or in another database, each day, then calculate the difference and use that as my number of new listings?
"Would it be possible to save my query count in a file, or in another database, each day, then calculate the difference and use that as my number of new listings?"
I understand that you can't change the table structure to add a date...so instead, I suggest to have a cron job at midnight that will create a record with a date and the higher ID at this moment. This way, you will be able to finde a range of ID for a specific date...
If you relayed on query count, you will get problem when you will start to delete some rows...

New records since last query in MySQL View

I am looking for a way to create a View that when queried will automatically only retrieve new records since the last query. My tables have a timestamp field for all entries, so for a simple example I can
SELECT * WHERE timestamp >= 'blah'
but I don't know how to determine what blah should be from the last query. So if the View was queried at 11:00 and then again at 12:00, the query at 12:00 should only return records added since 11:00. And so on... This all needs to be accomplished in the View, the end user should simply be able to query the View and get the results.
Is this possible?
There are two ways:
Store last access date time in database per user persistent session
table, if you have one. On next view call to database, use the
previous latest access time in the session to filter rows starting
from.
Store last access date time in user virtual session at client
environment. On every call to server, send last access date time as
well. So that server uses it to filter rows starting from.
I prefer to use second option that process won't write any data in database tables.
As there may be an unread record that slips through undetected (say it came less than a second since the last one accessed, so it has the same timestamp), set a column to auto increment (typically labelled id) and check for entries using it e.g. in PHP save the last accessed record in a $lastId variable, and use:
$sql="SELECT * WHERE `id` > '$lastId'";