SQLite in iPhone:I want to Retrieving 1 row for each date from sqlite - iphone

i only want to know that whether data is available for any specific date or not.If there are more than one data with the same date, i do not want to fetch all the data.I try to use
LIMIT 0,1 in where clause but it means it will fetch total 1 data for the given date range.
So please tell me the way to fetch data between a date range with 1 data for particular date.
Thanks.

Very simple example:
CREATE TABLE(
name,
date
);
insert into events values ("foo", "2008-01-01");
insert into events values ("bar", "2008-01-01");
insert into events values ("goo", "2009-01-01");
insert into events values ("gai", "2009-01-01");
select max(name), date from events group by date;
Output:
foo|2008-01-01
goo|2009-01-01
See How to select the first/least/max row per group in SQL

Related

Pulling the latest record when there are multiple records with different dates in Oracle HCM

I am written a query which pulls work schedule data on person level in Oracle Fusion HCM. What is the filter or the join condition which I need to add to pull the latest date column.
I have used the tables
PER_SCHEDULE_ASSIGNMENTS PSA
, ZMM_SR_SCHEDULES_TL ZSST
, PER_ALL_ASSIGNMENTS_M PAAM
, PER_ALL_PEOPLE_F PAPF
The query returns 4 rows with different dates. How to return only 1 row which has the latest date column in it?
Use SYSDATE BETWEEN EFFECTIVE_START_DATE AND EFFECTIVE_END_DATE in all the tables where the date start date is there.
This will get you the current row as of today from those tables. You won't have any duplicates anymore.

Is there a way to pull just the Year out a VARCHAR datetime value?

I am working on a project, in Snowflake, that requires me to combine pest & weather data tables, but the opposing tables do not share a common column. My solution has been to create a view that extracts the year from the Pest Table dates, format ex.
CREATION_DATE: 03/26/2020 09:11:15 PM,
to match the YEAR column in the Weather tables, format ex.
DATEYEAR: 2021.
However, I have come to find that the dates in the pest report are VARCHAR as opposed to traditional date/datetime values. Is there a way to pull just the Year out the VARCHAR date value? Additional information: I cannot change the tables themselves, I will need to create a view that preserves all other columns and adds a new "DATEYEAR" column.
Yes , we can and below is working example:
create table test (dt string );
insert into test(dt) values ('01/04/2022');
Select dt, DATE_PART( year, dt::date) from test
To make it easy, you can split the string into an array and take the third member of the array (using 2 since arrays are 0 based):
select strtok_to_array('03/26/2020', '/')[2]::int as MY_YEAR;

Power Query - Subtract the earliest date in one column from the record-specific date in another column

Every month I download a set of data into a report. That data consists of multiple records and each record has a record specific date as well as having the month end report date on the record's data-row.
I have used Power Query to upload all of these month end reports. I want use Power Query to be able to compare the column of record dates with the earliest date in the column of report dates to see if anybody has fiddled any data entry. The query table has the following headings.
Record ID Record Date Report Date
I've tried adding a custom column using the formula = if Record Date < List.Min(Report Date) then "Old" else "New"
this didn't work and I've spent ages trying to get a solution. I've also tried using Groups to get the minimum value, but I lose all of the other columns, which I want to keep. Any help really appreciated.
You have to refer to the fields in [], so here [Report Date]
To pick a column use Source[Field], so here #"PriorStep"[Report Date]
The List.Min function is not pulling as a number so you cant use <
Insert a Number.From in front of the calculation to convert to number
Same need to add Number.From in front of [Record Date] pulling as a date
Combined code:
#"Added Custom" = Table.AddColumn(#"PriorStep", "Custom", each if Number.From([Record Date])<Number.From(List.Min(#"PriorStep"[Report Date])) then "Old" else "New")

Cast varchar as date select distinct top 100

I am trying to fix a query that has come to light in SSRS after the new year. We have an input that comes from another application. It grabs a date and stores it as varchar. The SSRS report then fetches the top 100 'dates' but when 2017 dates have come around, this are not in the top 100.
The existing query is as follows
SELECT DISTINCT TOP (100)
FROM DenverTempData
ORDER by BY Date DESC
The date is stored as VARCHAR. So obviously this query doesn't grab a value such as 01012017 as being a top 100 (over values likes 12312016). I thought maybe I can simply change the datatype on this column to datetime. But the information comes from a flat file and is converted, so it's a little more difficult that that. So I'm hoping to do a select of the distinct top 100 while converting the date column to datetime or just date and grabbing the last 100 dates.
Can someone help with the query syntax? I'm thinking a cast to convert varchar to date, but how do I format with distinct top 100? I'm simply looking to retrieve the last 100 dates in chronological order from a column that is stored as varchar but contains a string representing a date.
Hopefully that makes sense
It is always a bad idea to store a date as string. This is highly culture specific!
You can cast your formatted string-date to a real date like this:
DECLARE #DateMMDDYYYY VARCHAR(100)='12312016';
SELECT CONVERT(DATE,STUFF(STUFF(#DateMMDDYYYY,5,0,'-'),3,0,'-'),110)
After the conversion your sorting (and therefore the TOP 100) should work as expected.
My strong advise: Try to store your dates in a column of a real date type to avoid such hassel!
SELECT DISTINCT TOP 100 (CAST(VarcharColumn as Date) as DateColumn)
FROM TABLE
Order by DateColumn desc

From and To date in calendar selector not fetching required data

I created calendar selector on date attribute.
when I select only From date, I get a message'No data returned for this view'.
when I select only To date,I am able to fetch all data values.
when I select From date and To date together, I get a Message "No data returned for this view".
when I run the report without any date selection (empty dates), I am able to fetch all data values.
I need related data values between From date and To date as per date selection.