I have a list of items I'd like to view by the date they most recently occurred. I am currently using this query.
SELECT Cleaning1, Max(Date1) AS most_recent
FROM CleaningLog
GROUP BY Cleaning1;
It worked yesterday when I was at work, but suddenly stopped working. It won't show to most recent date an event occurred for some of the items. I was wondering why this would suddenly stop working. I added date parameters to the four queries I have with this code. When that stopped working correctly, I decided to create a test query, without date parameters, and it still won't show me the most recent event that I typed in.
I tried playing around with the <, >, = signs in the date portion of the code, but nothing seems to capture the dates I added this morning. I should mention this is what I have for codes that have a date parameter:
SELECT Cleaning1, Max(Date1) AS most_recent
FROM CleaningLog
GROUP BY Cleaning1
HAVING Max(Date1) < Now() - 30;
What do you think would be a potential cause for this query to stop capturing dates? The dates in my database are not in chronological order, because I had to manually type in events that occurred in the past. Any help would be appreciated!
It seems like it won't use the data after ID 89. It worked fine yesterday afternoon. I added from ID 59 on this morning. All of the data was added the same way, through a form:
Convert your text date to a true date:
SELECT
Cleaning1,
Max(CDate(Date1)) AS most_recent
FROM
CleaningLog
GROUP BY
Cleaning1
HAVING
Max(CDate(Date1)) < Date() - 30;
Related
I am trying to find a certain field(timestamp) for today to send in a report. The code I have been using only returns back 4 results. I do not think that is right. I was thinking about using a wildcard for the timestamp seconds,milliseconds part...I don't want the seconds part hence my current code, I just want the results for the current date. I also tried select current_timestamp(processed_time) as now; to no avail.
SELECT *
FROM `prod.ods_simp.audit`
WHERE DATE(processed_time) = DATE(TIMESTAMP('2020-04-06')) or date(next_transmission) = DATE(TIMESTAMP('2020-04-06'))
LIMIT 1000;
Moving from comments to answer for closing:
Instead of DATE(TIMESTAMP('2020-04-06')) you can save code and time with DATE('2020-04-06').
And even better and shorter:
WHERE DATE(processed_time) = '2020-04-06'
(BigQuery auto-casts to DATE in this case)
I have developed a large piece of coding, to get order information from our database. This has previously been working fine, capturing 1000s of lines of data in less than a second.
However, recently the specification has changed. We have moved from being Monday to Monday to the intention of running our orders from Saturday through Friday.
This has meant rewriting the code including case statements the following is an example:
*(Previous)*
,Case When To_Char(obd.due_date, 'YYYYIW') = To_Char(sysdate, 'YYYYIW') Then 'Current Week'
*(Now)*
,Case When TO_DATE(obd.due_date, 'DD-MM-YYYY') BETWEEN (TO_DATE(TO_CHAR(TRUNC(TO_DATE(SYSDATE,'DD-MM-YYYY'), 'WW')-2,'DD-MON-YYYY'))) AND (TO_DATE(TO_CHAR(TRUNC(TO_DATE(SYSDATE,'DD-MM-YYYY'), 'WW')+5,'DD-MON-YYYY'))) Then 'Current Week'
However I now lose the index on the fields due to conversion and thus the time for the data to be accessed has increased dramatically.
Any help would be greatly appreciated.
I doubt that your "previous" calculation used an index (and it's used in a CASE, not a WHERE).
You should always try to get a searchable argument, i.e. calculation only on one side of the comparison:
WHEN obd.due_date >= next_day(trunc(current_date) , 'sat')-7
AND obd.due_date < next_day(trunc(current_date) , 'sat')
should be what you want
I've been searching the web and asked around, but can't seem to find an answer to my problem...
I have a running ODBC connection with my FrontBase database in OpenOffice Base. I manage to select everything I want, but when I only want to show the records between certain dates, or even one date I keep on getting a Semantic Error.
Here's my query:
SELECT * FROM "SALES" WHERE "DATE" = '2014-04-01'
Just in case you suggest using # for the date, it doesn't work either
DATE '2014-04-01' is also unsuccessful :(
Anyone have any ideas?
After a lot of trial and errors I took a closer look at the OpenOfficeBase interface. I was sure nothing was wrong with my statement so there must be something in Base that I'm missing.
In the toolbar there's a button with SQL and a checkmark which says "Execute SQL-command immediatly". Thought it wouldn't do any harm if I enabled it and gave it a try. And there it was, my query with date filter! I have no idea why that button is there or what it's exact function is, but enabling it made my query work.
Thanks anyway for the suggestions, but apparently we've got to look further than just the language ;-)
A shot in the dark here. Youŕe using a FrontBase database, googling on "Frontbase select date range" gave me this page: http://www.frontbase.com/documentation/LookSeeIntro-2.3.html
There they have this example query:
SELECT
receiver FROM memo_mails
WHERE
sender = 'QA' AND
CAST(dateSent AS DATE) < DATE '2001-06-01' AND
SATISFIES(quickx, 'Periscope & invoice');
So based on that example, I would try
SELECT
* FROM "Sales"
WHERE
(CAST("Sales"."SalesDate" AS DATE) >= DATE '2014-06-01') AND
(CAST("Sales"."SalesDate" AS DATE) <= DATE '2014-06-30');
SELECT * FROM SALES WHERE DATE = '2014-04-01'
The above should work as long as there is no time in the column you are trying to select from. Whats the columns data type?
If you're still looking for answers
SELECT * FROM "SALES" WHERE "DATE" = {D '2014-04-01'} It seems that one should put the letter D to signify that it is a date and not a string/varchar. I hope this helps, even though the question is 1 year old.
I have a field in a table called DATEF. It displays dates as follows: 2013-11-25 08:30:00.000. The field is used to show appointment dates. What I need to show are future appointment dates from today or = to today. (Getdate) for some reason this is not working for me today. Appreciate the help. Thank you.
Try this... you're probably failing to factor in the time component. (This is for SQL Server, you'll have to find the equivalent for your respective environment)
SELECT <SOMETHING>
FROM TABLE
WHERE DATEF >= CONVERT(DATE,GETDATE())
Could somebody recommend the query to retrieve records up to today or certain dates?
I'm required to produce an Oracle report where user needs to enter a date and records up to that date will be shown.
I tried
select * from the_table where the_date <= sysdate
However it seems to produce an inaccurate result. What is the better query for this. For now I'm just playing around with sysdate. Later I will need to use a certain date keyed in by the user and all the records up to that date needs to be shown.
Any suggestions?
Sometimes you get inaccurate records because of little differences like minutes and seconds when two dates have the same day/month/year. Try the following
select * from the_table where TRUNC(the_date) <= sysdate
The TRUNC removes the minute and the seconds. Sometimes you get inaccurate records without using that