Data validation on curdate() group by error code 1111 - mysql

This is relatively easy but I've been staring at the code too long and making mistakes. I need to validate that a table has been populated for the day and the query simply takes today's date - curdate() - against the date_pulled column but I'm getting Error Code: 1111. Invalid use of group function. Where am I messing up.
select * from test where max(date(date_pulled))=curdate();

you dont need max here. you already telling the query to choose the date which is equal to current date.
try that:
select * from test where date(date_pulled)=curdate();

Related

Unable to get Results of a query

I am newbie to SQL.
I have this query
I am not sure where i am doing it wrong.
Can you guys help me out?
thanks.
Three mistakes:
You need single quotes
MySql expects two-digit months
The 2015-09-30 end date includes an implicit midnight for the time component, which excludes most of the day
Put it all together you get this:
SELECT * FROM results WHERE played_on BETWEEN '2015-09-01' AND '2015-10-01';
While I'm here, I prefer to avoid BETWEEN in favor of explicit bounds. There's always that chance someone codes a game for exactly midnight October 1:
SELECT * FROM results WHERE played_on >= '2015-09-01' AND played_on < '2015-10-01';
And you would have had this answer faster if I could have copy/pasted the query text from your post instead of having to re-type. Posting images of sample data or code instead of the text is considered very rude here.
i think you can use MySql Date Function like MONTH() and YEAR() for this query :
SELECT * FROM results WHERE MONTH(played_on) = 9 AND YEAR(played_on) = 2015
I hope this answer can help you.

MySQL "date_sub(now(), INTERVAL X" Error Code: 1366 Incorrect string value: '\xEF\x80\xA6Top...' for column 's' at row 3

I have a problem here thats really puzzling me. I have a MySQL query, that works fine.. for the most part. In the query, Im looking at dates and date ranges from a table, and returning results that are X days old from today. It looks like this:
WHERE tickets.date_created > date_sub(now(), INTERVAL 30 DAY)
Under most conditions, the query works fine. However, if I change the interval to a number between 80 to 97 my script fails to execute. The error I get is:
Error Code: 1366 Incorrect string value: '\xEF\x80\xA6Top...' for column 's' at row 3
Also, tryin 3 months, rather than 90 days doesnt work. There appear to be other numbers in the 100's that dont work too, however, if I set something like 10000 days, all results return ok.
Is this something in my database? Is it my query? Has anyone seen this with a date interval? What am I doing wrong?
Any thoughts anyone has :)
Many thanks!
I've found the answer!
There is a function built into our MySQL to strip out HTML and other characters from a returned result. Whilst its not performing any action on the date area (or shouldn't be) as its in my select statement:
mycleanup (left(tickets_messages.message, 250))
It appears that if I change this to simply
left(tickets_messages.message, 250)
My query then works! Very odd, but I guess Ill have to find another way to work around stripping HTML and the like.

MySQL Convert 48 Hours into 48:00:00

I have a regular DATETIME row, eg: 2012-06-19 13:56:56
I am running the following to see how much the time difference is:
DATEDIFF(end_time, NOW()) * 24
It returns 48
Edit: How do I get the Minutes/Seconds? I have tried UNIXTIME(field) - UNIXTIME(NOW()) but i cant get beyond it.
Im trying to convert this into 48:00:00 (Or however that timestamp works)
I keep looking up time functions but they have to do with EXTRACT, and Im not sure thats the way to go about it.
Since datediff only ever returns a difference in days, you might as well just use a string operation to do your formating:
SELECT CONCAT(DATEDIFF(end_time, NOW()) * 24), ':00:00')

Trying to use BETWEEN condition to return rows based on date but getting no results

I have a database containing a list of events, it is formatted something like this:
Datef Event Location Discipline
10/01/2012 MG Training Brooklands MG
I am running this query in order to get the results between certain dates:
SELECT * FROM events WHERE Discipline IN ('MG') AND Datef BETWEEN 01/01/2012 AND 31/01/2012
The query runs correctly and I know that there are relevant results in the database, but I receive no results when running the query in phpmyadmin (I just get told "Your SQL query has been executed successfully").
I was wondering if anyone had any idea why this wouldn't be returning results?
Update:
Putting dates in quotes (e.g. SELECT * FROM events WHERE Discipline IN ('MG') AND Datef BETWEEN 01/01/2012 AND 31/01/2012) kinda works but there's a bug.
I've certain dates doesn't work. e.g. SELECT * FROM events WHERE Discipline IN ('COMM') AND Datef BETWEEN '2012-02-01' AND '2012-02-29' shows no results, even though there is an event on 2010-02-01. Is this a peculiarity in the BETWEEN algorithm, or am I still getting my query wrong?
Without quotes or anything designating those values as dates, it will simply do the math on the integers you wrote.
In other words, you ask for
BETWEEN 01/01/2012 AND 31/01/2012
So you get 1/1=1, then 1/2012 which is almost 0.
Then you do 31/1=31, then 31/2012 which is also almost 0.
So it becomes
BETWEEN 0 and 0
Try wrapping your code strtotime(). MySQL and PHP use different formatting.
For some additional info, here are a couple of links:
http://www.richardlord.net/blog/dates-in-php-and-mysql
http://www.binarytides.com/blog/parse-and-format-dates-between-php-and-mysql/
Your column Datef is of the wrong type and should be datatime
SELECT
*
FROM
`events`
WHERE
`Discipline` IN ('MG')
AND
`Datef` BETWEEN '2012-01-01' AND '2012-01-31'

mysql calculation

This is my initial question....well I got a response but I'm still stuck.
Can anyone please explain how can I achieve this in mysql:
I have two fields in mysql, 'cap_commdate' with DATE TYPE and 'cap_policyterm' with INT TYPE. I want to have another field called 'cap_maturityDate' which will automatically compute the policy term pereod in years (in layman's term ie: cap_commdate*cap_policyterm). What is the right SQL query to use; or what is the best approach; and I want to use it in my recordset to prepare a confirmation page... please a simple explanation...
I have tried the following:
SELECT DATE_ADD(cap_commdate, INTERVAL cap_policyterm YEAR) ...
I ran the query and got errors; so i edited it and used:
SELECT
DATE_ADD("cap_commdate", INTERVAL "cap_policyterm" YEAR) AS cap_maturity FROM capital
All I got was empty fields. Please help out.
It sounds like you want this:
SELECT DATE_ADD(cap_commdate, INTERVAL cap_policyterm YEAR)
...
This DATE_ADD function adds the given number of years to the starting date, thus producing the maturity date — just as you've described.
Please show the errors you get. The query
SELECT DATE_ADD(cap_commdate, INTERVAL cap_policyterm YEAR) FROM capital
should work.