Sponsored Content
Top Forums Programming MYSQL query search between dates Post 302926639 by Ditto on Tuesday 25th of November 2014 02:43:11 PM
Old 11-25-2014
Quote:
Originally Posted by figaro
A nested query must have an alias, so I added 'X' as the alias in your code:

Code:
select id, 'today', 'monthago', today, monthago 
from ( 
SELECT id, stdate, DATE_SUB(CURDATE(), INTERVAL 1 month) as monthago, CURDATE() as today  
FROM data_table X)

As regards your earlier question, in MySQL and other databases too, there is a difference between single quote (') and backquote (`). I think you meant to use the latter, which is what Ditto was getting at.
I'm an Oracle guy, not very familiar with MYSQL .. Smilie I was thinking his issue was the fact that:

where column = 'today'

is not the same as:

where column = today

if today is some internal function, then you probably shouldn't use single quotes ... if MYSQL uses back quotes ` .. then yeah, sure Smilie but I was making an assumption MYSQL treats single or double quotes as strings.

which would be like trying to match:

where Nov 25, 2014 = "today" ..

as opposed to:
where Nov 25, 2014 = Nov 25, 2014
(ie where date_col = today ) ??

In Oracle it's:

where date_col = sysdate

but that's another story Smilie
 

6 More Discussions You Might Find Interesting

1. Programming

How to query one to many mysql

Hi there, I have a hierarchical database that include 4 tables. Table A is the parent of B, B is Parent of C, C is parent of D. If I want to query everything in D that is associated with A.name, how do I do that? Thanks! YanYan (0 Replies)
Discussion started by: pinkgladiator
0 Replies

2. Web Development

mysql query help

hello all i have 2 columns every column in the following format column1 2011-04-01 11:39:54 column2 2019-02-03 00:00:00 i want get difference between above data as following 2 days 11:39 how to do so ? i tried many functions but nothing works please advice what is the query... (6 Replies)
Discussion started by: mogabr
6 Replies

3. Shell Programming and Scripting

mysql query in shellscript

Hi, I want to run below query on shellscript but having one problm. ADV=$( mysql -h "$IP_ADDR" -u "$USER_NAME" "$TABLE_NAME" -BNe" SELECT ADV FROM indata where inid='$INSTRUID' and Date='$latest Date';" ) here Date column contans different below dates 2011-12-01... (11 Replies)
Discussion started by: aish11
11 Replies

4. Programming

mysql query help

Hello i have created mysql query to compare to values and get difference in percentage as following: SELECT file_name, 100 - ((100 * (SELECT file_count FROM xipi_files z WHERE x.file_group = z.file_group AND x.file_name = z.file_name AND z.insert_date = CURDATE( ) - INTERVAL 1 DAY)) /... (1 Reply)
Discussion started by: mogabr
1 Replies

5. Shell Programming and Scripting

Search pattern on logfile and search for day/dates and skip duplicate lines if any

Hi, I've written a script to search for an Oracle ORA- error on a log file, print that line and the .trc file associated with it as well as the dateline of when I assumed the error occured. In most it is the first dateline previous to the error. Unfortunately, this is not a fool proof script.... (2 Replies)
Discussion started by: newbie_01
2 Replies

6. Programming

Need help in mysql query

Hi All, i have a table in mysql with the following data Table name Test Assettype Serial_No Status location Mouse 123456 In Stock chennai Mouse 98765 Allocated chennai Keyboard ... (2 Replies)
Discussion started by: venkitesh
2 Replies
NNGOBACK(1)						      General Commands Manual						       NNGOBACK(1)

NAME
nngoback - make news articles unread on a day-by-day basis (nn) SYNOPSIS
nngoback [ -NQvi ] [-d] days [ group ]... DESCRIPTION
nngoback will rewind the .newsrc record file of nn(1) one or more days. It can be used to rewind all groups, or only a specified set of groups. In other words, nngoback can mark news articles which have arrived on the system during the last days days unread. Only subscribed groups that occur in the current presentation sequence are rewound. That means that if no group arguments are specified, all groups occurring in the sequence defined in the init file will be rewound. Otherwise, only the groups specified on the argument line will be rewound. When a group is rewound, the information about selections, partially read digests etc. are discarded. It will print notifications about this unless the -Q (quiet) option is used. If the -i (interactive) option is specified, nngoback will report for each how many articles can be marked unread, and ask for confirmation before going back in that group. If the -v (verbose) option is specified, nngoback will report how many articles are marked unread. If the -N (no-update) option is specified, nngoback will perform the entire goback operation, but not update the .newsrc file. If you are not up-to-date with your news reading, you can also use nngoback to catch up to only have the last few days of news waiting to be read in the following way: nn -a0 nngoback 3 The nn command will mark all articles in all groups as read (answer all to the catch-up question.) The following nngoback will then make the last three days of news unread again. Examples: nngoback 0 Mark the articles which have arrived today as unread. nngoback 1 Mark the articles which have arrived yesterday and today as unread. nngoback 6 Mark the articles which have arrived during the last week as unread. You cannot go more than 14 days back with nngoback. (You can change this limit as described below.) THE BACK_ACT DAEMON It is a prerequisite for the use of nngoback that the script back_act is executed at an appropriate time once (and only once) every day. Preferably this is done by cron right before the bacth of news for `today' is received. back_act will maintain copies of the active file for the last 14 days. Optionally, the back_act program accepts a single numerical argument specifying how many copies of the active file it should maintain. This is useful if news is expired after 7 days, in which case keeping more than 7 days of active file copies is wasteful. FILES
~/.newsrc The record of read articles. ~/.newsrc.goback The original rc file before goback. $db/active.N The N days `old' active file. $master/back_act Script run by cron to maintain old active files. SEE ALSO
nn(1), nncheck(1), nngrab(1), nngrep(1), nnpost(1), nntidy(1) nnadmin(1M), nnusage(1M), nnmaster(8) NOTES
nngoback does not check the age of the `old' active files; it will blindly believe that active.0 was created today, and that active.7 is really seven days old! Therefore, the back_act script should be run once and only once every day for nngoback to work properly. The days are counted relative to the time the active files were copied. AUTHOR
Kim F. Storm, Texas Instruments A/S, Denmark E-mail: storm@texas.dk 4th Berkeley Distribution Release 6.6 NNGOBACK(1)
All times are GMT -4. The time now is 11:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy