Sponsored Content
Full Discussion: SQL datetime calculation
Top Forums Programming SQL datetime calculation Post 302516431 by figaro on Saturday 23rd of April 2011 04:32:39 AM
Old 04-23-2011
SQL datetime calculation

Suppose I have a mysql table consisting of measurements taken during irregular intervals as follows:

Code:
CREATE TABLE data (datetime DATETIME, value INTEGER);

mysql> SELECT datetime, value FROM data;
+---------------------+---------+
| datetime            | value   |
+---------------------+---------+
| 2010-09-12 13:25:38 |   41538 | 
| 2010-09-12 13:25:55 |   41543 | 
| 2010-09-12 23:01:06 |   43364 | 
| 2010-09-12 23:01:46 |   43365 | 
| 2010-09-12 23:02:40 |   43366 | 
| 2010-09-12 23:02:48 |   43367 | 
| 2010-09-16 19:13:50 |   75538 | 
| 2010-09-16 19:19:27 |   75539 | 
+---------------------+---------+

What I would like to do is select the values which are the maximum in their minute, so the output should be as follows:

Code:
41543
43365
43367
75538
75539

So 41543 is selected because its datetime is 2010-09-12 13:25:55, which is after 2010-09-12 13:25:38. How do I achieve this?
 

10 More Discussions You Might Find Interesting

1. Programming

SQL datetime calculations

Suppose I have a table as follows: CREATE TABLE data ( `datetime` datetime DEFAULT NOT NULL, `temperature` float DEFAULT NO NULL ); populated with temperature samples of a couple times a second. Let's say I want to find the temperatures which are 1 second apart: SELECT D1.datetime,... (3 Replies)
Discussion started by: figaro
3 Replies

2. Shell Programming and Scripting

datetime.pm

Hi, I'm trying to use datetime.pm function in Perl. I do not have in the library. Is there a way to get it and put it into library? Thanks, George. (1 Reply)
Discussion started by: gpaulose
1 Replies

3. Shell Programming and Scripting

Datetime Format 'yyyymmddmiss' Calculation

Given a time format yyyymmddmiss 201007221403 How can I add or minus minutes such that it becomes 201007221348 when I minus away 15 minutes from the time? Also, given a time frame, let say 10 days, how do I check if a date 201006231403 that is not more than 10 days behind... (3 Replies)
Discussion started by: alienated
3 Replies

4. Shell Programming and Scripting

Awk new datetime everyline

Hi, I'm using awk in HP-UX machine which does not support systime(), strftime(). So to get the date time I was using : seq 1 100000 | awk ' "date +%Y%m%d%H%M%s" | getline curtime; print curtime }' However the above code gets the date only once, next time it is not updated. For... (2 Replies)
Discussion started by: Random_Net
2 Replies

5. Shell Programming and Scripting

How to generate datetime string?

Hi. I'm hoping there is a simple method where I'm able to generate a datetime string that looks like this (yyyymmddhhmm): 201106280830 The tricky part would be that I need this string to be today's datetime minus 1 year. Is there anyway to do this? (3 Replies)
Discussion started by: buechler66
3 Replies

6. Shell Programming and Scripting

How to compare datetime?

Hi, To get the batch status, I will need to check if the particular job started after 5PM. if the job start time is before 5 pm, then it means that the job has not started for this particular date. I will run the script with date as argument. For eg: BS 07/10/2012 Start time from the log is... (8 Replies)
Discussion started by: ajayakunuri
8 Replies

7. Shell Programming and Scripting

Adding 48 hours to DateTime

Hey Guys, I have looked for a solution throughout the forum for my particular question, but I cant find one. So I'm sorry if I overlooked it. I need to be able to 48 add hours to a particular DateTime string. I have a variable named $startTime I would like to be able to take that... (1 Reply)
Discussion started by: chagan02
1 Replies

8. AIX

AIX DateTime Computation

Good day people, Kindly advice on below please. 1) Formatting/ Arithmetic operation of given date I understand from the AIX man date and some research that flag -d is not applicable for AIX shell scripting and some of the UNIX command date command is not available in AIX. Please advice... (1 Reply)
Discussion started by: cielle
1 Replies

9. UNIX for Dummies Questions & Answers

Find files between two datetime..

Hi All, How do i find all the files between two times. Eg: 26 may 2014 06:00 to 26 may 2014 14:00 mmin and mtime gives for a specific period. we receive hundreds of files input directories and i need to find how many files are received between given specific datetime. Thanks. (2 Replies)
Discussion started by: abhi_123
2 Replies

10. Shell Programming and Scripting

Filename with datetime

Hello All, I need unix command to generate a file with datetime in it. For example : ABC_YYYYMMDDHH24MISS.txt Regards Biswajeet Ghosh (1 Reply)
Discussion started by: bghosh
1 Replies
DRIZZLEDUMP(1)							      Drizzle							    DRIZZLEDUMP(1)

NAME
drizzledump - a database backup program SYNOPSIS
drizzledump [OPTIONS] database [tables] drizzledump [OPTIONS] --databases DB1 [DB2 DB3...] drizzledump [OPTIONS] --all-databases DESCRIPTION
drizzledump is used for backing up and restoring logical backups of a Drizzle database, as well as for migrating from a more traditional MySQL server. When connecting to a Drizzle server it will do a plain dump of the server. When connecting to a MySQL server, it will automatically detect this, and will convert the dump of the tables and data into a Drizzle compatible format. Any binary data in tables will be converted into hexadecimal output so that it does not corrupt the dump file. DRIZZLEDUMP OPTIONS
The drizzledump tool has several available options: --all-databases, -A Dumps all databases found on the server apart from information_schema and data_dictionary in Drizzle and information_schema, perfor- mance_schema and mysql in MySQL. --force, -f Continue even if a sql-error is received. --help Show a message with all the available options. --lock-all-tables, -x Locks all the tables for all databases with a global read lock. The lock is released automatically when drizzledump ends. Also turns on --single-transaction. --single-transaction Creates a consistent snapshot by dumping the tables in a single transaction. During the snapshot no other connected client should use any of the following as this will implicitly commit the transaction and prevent the consistency: ALTER TABLE DROP TABLE RENAME TABLE TRUNCATE TABLE Only works with InnoDB. --skip-opt A shortcut for --skip-drop-table, --skip-create, --skip-extended-insert and --skip-disable-keys --tables t1 t2 ... Dump a list of tables. --skip-drop-table Do not add a 'drop table' before each create. --show-progress-size rows (=10000) Show progress of the dump every rows of the dump. Requires --verbose --verbose, -v Sends various verbose information to stderr as the dump progresses. --skip-extended-insert Dump every row on an individual line. For example: INSERT INTO `t1` VALUES (1,'hello'); INSERT INTO `t1` VALUES (2,'world'); This is useful for calculating and storing diffs of dump files. --skip-dump-date Do not display the date/time at the end of the dump. --no-defaults Do not attempt to read configuration from configuration files. --add-drop-database Add DROP DATABASE statements before CREATE DATABASE. --compact Gives a more compact output by disabling header/footer comments and enabling --skip-disable-keys. --databases, -B Dump several databases. The databases do not need to follow on after this option, they can be anywhere in the command line. --skip-disable-keys, -K Do not dump the statements ALTER TABLE ... DISABLE KEYS and ALTER TABLE ... ENABLE KEYS --ignore-table table Do not dump specified table, needs to be in the format database.table. Can be specified multiple times for multiple tables. --insert-ignore Add the IGNORE keyword into every INSERT statement. --no-autocommit Make the dump of each table a single transaction by wrapping it in COMMIT statements. --no-create-db, -n Do not dump the CREATE DATABASE statements when using --all-databases or --databases. --skip-create, -t Do not dump the CREATE TABLE statements. --no-data, -d Do not dump the data itself. Used to dump the schemas only. --replace Use REPLACE INTO statements instead of INSERT INTO --destination-type type (=stdout) Destination of the data. stdout The default. Output to the command line database Connect to another database and pipe data to that. New in version Drizzle7: 2010-09-27 --destination-host hostname (=localhost) The hostname for the destination database. Requires --destination-type = database New in version Drizzle7: 2010-09-27 --destination-port port (=3306) The port number for the destination database. Requires --destination-type = database New in version Drizzle7: 2010-09-27 --destination-user username The username for the destinations database. Requires --destination-type = database New in version Drizzle7: 2010-09-27 --destination-password password The password for the destination database. Requires --destination-type = database New in version Drizzle7: 2010-09-27 --destination-database database The database for the destination database, for use when only dumping a single database. Requires --destination-type = database New in version Drizzle7: 2010-09-27 --my-data-is-mangled If your data is UTF8 but has been stored in a latin1 table using a latin1 connection then corruption is likely and drizzledump by default will retrieve mangled data. This is because MySQL will convert the data to UTF8 on the way out to drizzledump and you effectively get a double-conversion to UTF8. This typically happens with PHP apps that do not use SET NAMES. In these cases setting this option will retrieve the data as you see it in your application. New in version Drizzle7: 2011-01-31 --host, -h hostname (=localhost) The hostname of the database server. --user, -u username The username for the database server. --password, -P password The password for the database server. --port, -p port (=4427) The port number of the database server. --protocol protocol (=mysql) The protocol to use when connecting to the database server. Options are: mysql The standard MySQL protocol. drizzle The Drizzle protocol. BACKUPS USING DRIZZLEDUMP
Backups of a database can be made very simply by running the following: $ drizzledump --all-databases > dumpfile.sql This can then be re-imported into drizzle at a later date using: $ drizzle < dumpfile.sql MYSQL MIGRATION USING DRIZZLEDUMP
As of version 2010-09-27 there is the capability to migrate databases from MySQL to Drizzle using drizzledump. drizzledump will automatically detect whether it is talking to a MySQL or Drizzle database server. If it is connected to a MySQL server it will automatically convert all the structures and data into a Drizzle compatible format. Warning drizzledump will by default try to connect via. port 4427 so to connect to a MySQL server a port (such as 3306) must be specified. So, simply connecting to a MySQL server with drizzledump as follows will give you a Drizzle compatible output: $ drizzledump --all-databases --host=mysql-host --port=3306 --user=mysql-user --password > dumpfile.sql Additionally drizzledump can now dump from MySQL and import directly into a Drizzle server as follows: $ drizzledump --all-databases --host=mysql-host --port=3306 --user=mysql-user --password --destination-type=database --desination-host=drizzle-host Note Please take special note of old-passwords-label if you have connection issues from drizzledump to your MySQL server. Note If you find your VARCHAR and TEXT data does not look correct in a drizzledump output, it is likely that you have UTF8 data stored in a non-UTF8 table. In which case please check the --my-data-is-mangled option. When you migrate from MySQL to Drizzle, the following conversions are required: o MyISAM -> InnoDB o FullText -> drop it (with stderr warning) o int unsigned -> bigint o tinyint -> int o smallint -> int o mediumint -> int o tinytext -> text o mediumtext -> text o longtext -> text o tinyblob -> blob o mediumblob -> blob o longblob -> blob o year -> int o set -> text [1] o date/datetime default 0000-00-00 -> default NULL [2] o date/datetime NOT NULL columns -> NULL [2] o any date data containing 0000-00-00 -> NULL [2] o time -> int of the number of seconds [3] o enum-> DEFAULT NULL [4] FOOTNOTES
[1] There is currently no good alternative to SET, this is simply to preserve the data in the column. There is a new alternative to SET to be included at a later date. [2] Currently, ALL date columns have their DEFAULT set to NULL on migration. This is so that any rows with 0000-00-00 dates can convert to NULL. [3] This prevents data loss since MySQL's TIME data type has a range of -838:59:59 - 838:59:59, and Drizzle's TIME type has a range of 00:00:00 - 23:59:59. [4] This is so that empty entries such as '' will convert to NULL. AUTHOR
Andrew Hutchings COPYRIGHT
2010, Drizzle Developers 7 June 03, 2012 DRIZZLEDUMP(1)
All times are GMT -4. The time now is 11:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy