Sql query not working with date between [closed] - mysql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
My sql squery seems not be not working, any idea why?
SELECT
PH,
Chlorine,
Temperature,
Date,
Time
FROM googlechart
Where Date BETWEEN '2014-03-19' AND '2014-03-21' order by Date, Time;

Try this one:
SELECT
PH,
Chlorine,
Temperature,
Date,
Time
FROM googlechart
WHERE Date BETWEEN '2014-03-19' AND '2014-03-21'
ORDER BY Date, Time;
You have missed the WHERE.

Try like this
SELECT
PH,
Chlorine,
Temperature,
Date,
Time
FROM googlechart
Where Date BETWEEN cast('2014-03-19' as datetime)
AND cast('2014-03-21' as datetime) order by Date, Time;

Related

Query with Events was happening in march, 2007 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to solve this problem. But I have difficult working with dates, dates overlapping, whatever.
I would like to get all events that was happening in March, 2007.
My events table:
ID
name
start_date
end_date
I am trying:
SELECT *
FROM events
WHERE (MONTH(start_date)<=3 AND
YEAR(start_date)<=2007) AND (YEAR(end_date)>=2007 AND
MONTH(end_date)>=3)
Can you help me?
Normally, you would use:
where start_date < '2007-04-01' and end_date >= '2007-03-01'
This will give any event active during the month.
If you want events that are only in the month, then:
where start_date >= '2007-03-01' and end_date < '2007-04-01'

mysql event for selecting registration id [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
i need to insert reg_id of patient form first table (registration_table) to second table (patient_status) for those patient whose registration is done 30 days before
my query
INSERT INTO patient_status(reg_id) SELECT reg_id FROM registration_table
WHERE DATEDIFF(day,reg_date,getdate()) >= 30
it says
Incorrect parameter count in the call to native function 'DATEDIFF'
DateDIFF return the number of DAY so you need simply and in mysql you should use CURDATE() (getdate() should be from sql-server)
INSERT INTO patient_status(reg_id)
SELECT reg_id FROM registration_table
WHERE DATEDIFF(curdate(), reg_date ) >= 30
you're supplying a third parameter to your DATEDIFF(start,end) function.

mix 2 mysql date columns to one and order by [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a table "USER" in MySQL , some columns are "ID","Name","Birth" and "Death"... Birth and Death save date values.
I want to display both Birth and Death and then order by date ASC.
Here is an example from what I have and what I need..
column Birth:
1-2-99
2-2-99
column Death:
1-1-99
2-3-99
desired result from a query:
1-1-99 (from death col)
1-2-99 (from Birth col)
2-2-99 (from Birth col)
2-3-99 (from death col)
The example is displayed as (DD,MM,YY)
Use UNION or UNION ALL:
SELECT `date`
FROM
(
SELECT death AS `date` FROM tablename
UNION ALL
SELECT birth FROM tablename
) AS t
ORDER BY `date`;

MYSQL get last date from table that has not yet passed [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my database in table_a every row has a date_created like "2011-04-17"
Now some of these dates are in the past, but my question is how can I retrieve the latest date that has not yet passed?
Try this one
SELECT * FROM table_a WHERE CURDATE() <= date_created
CURDATE()
Returns the current date as a value in 'YYYY-MM-DD' or YYYYMMDD
format, depending on whether the function is used in a string or
numeric context.
Can you try this,
SELECT * FROM table_a WHERE date_created >= CURDATE()
IF date_created is a date datatype then you can use
SELECT *
FROM table_a
WHERE date_created >= NOW()
LIMIT 1

Need to create a query for monthly data [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to create a query in mysql to retrieve data where CREATED_DATE range should be 20th of current month to 20th of previous month. Please suggest..thanks
You can get dynamic records using current month, by the following query
SELECT * FROM table_name WHERE CREATED_DATE BETWEEN
DATE_FORMAT(NOW(),'%Y-%m-20') - INTERVAL 1 MONTH
AND DATE_FORMAT( NOW(),'%Y-%m-20')
Check the live result at the fiddle http://sqlfiddle.com/#!2/4668c/7
SELECT
*
FROM
your_table
WHERE
`CREATED_DATE` BETWEEN "2013-10-20" AND "2013-11-20";