I have a table that is built up as follows:
dpTicker dpDate dpOpen dpHigh dpLow dpClose dpVolume dpAdjClose dpCreated dpModified
GLE.PA 2016-02-01 35.39 35.455 34.375 34.785 2951300 34.785 2016-02-06 13:33:40 2016-02-06 13:33:40
GLE.PA 2016-02-02 34.515 34.565 32.165 32.575 7353600 32.575 2016-02-06 13:33:40 2016-02-06 13:33:40
GLE.PA 2016-02-03 32.4 32.495 30.885 31.6 7007000 31.6 2016-02-06 13:33:40 2016-02-06 13:33:40
GLE.PA 2016-02-04 32.075 32.38 30.67 31.98 8181000 31.98 2016-02-06 13:33:40 2016-02-06 13:33:40
GLE.PA 2016-02-05 32.55 33.0 31.86 32.11 7056700 32.11 2016-02-06 13:33:40 2016-02-06 13:33:40
The data is daily share price information and the table contains hundreds of tickers (eg GLE.PA). Each ticker (eg GLE.PA) has an entry for each "Business Day".
My objective is to query Monthly Price Summaries from this Daily Price data table. The monthly data is constructed as follows:
Month Open: dpOpen at the first business day of the month;
Month high: max(dpHigh) of the month;
Month Low: min(dpLow) of the month;
Month Close: dpClose at the last business date of the month.
I manage to query the data for a specific month by using the following query in SQLite3:
SELECT
strftime ('%Y-%m', dpDate) AS month,
(SELECT dpOpen
FROM DailyPrices
WHERE dpTicker = 'GLE.PA'
AND dpDate =
(SELECT min(dpDate)
FROM DailyPrices
WHERE strftime('%Y%m', dpDate) = '201509'
)
) AS Open,
max(dpHigh) AS High,
min (dpLow) AS Low,
(SELECT dpClose
FROM DailyPrices
WHERE dpTicker = 'GLE.PA'
AND dpDate =
(SELECT max(dpDate)
FROM DailyPrices
WHERE strftime('%Y%m', dpDate) = '201509'
)
) AS Close
FROM DailyPrices
WHERE dpTicker ='GLE.PA'
AND strftime('%Y%m', dpDate) = '201509';
The output of the query is as follows:
bash-3.2$ sqlite3 myShares < month.sql
month Open High Low Close
---------- ---------- ---------- ---------- ----------
2015-09 42.72 44.07 37.25 39.85
bash-3.2$
With the following query I manage to generate a monthly overview for the High and Low:
SELECT
strftime('%Y-%m', dpDate) AS Month,
max(dpHigh) AS High,
min(dpLow) AS Low
FROM DailyPrices
WHERE dpTicker ='GLE.PA'
GROUP BY strftime('%Y%m', update);
A snapshot of the output looks as follows:
bash-3.2$ sqlite3 myShares < monthly.sql
Month High Low
---------- ---------- ----------
2000-01 219.32 184.346
2000-02 206.43 181.977
2000-03 210.411 181.503
2000-04 221.405 197.805
2000-05 226.239 55.9199
...
With the following query, I manage to extract the correct Open and by analogy the correct Close data:
SELECT
strftime('%Y-%m', dpDate) AS Month,
dpOpen AS Open
FROM DailyPrices
WHERE dpTicker = 'GLE.PA'
AND dpDate IN
(SELECT min(dpDate)
FROM DailyPrices
WHERE dpTicker = 'GLE.PA'
GROUP BY strftime('%Y%m', dpDate)
);
A snapshot of the output is as follows:
bash-3.2$ sqlite3 myShares < Open.sql
Month Open
---------- ----------
2000-01 218.846
2000-02 200.269
2000-03 206.525
2000-04 201.312
2000-05 215.908
...
I am struggling to combine the queries, month.sql and open.sql, into one query to obtain the following output:
Month Open High Low Close
------- ----- ----- ----- -----
2015-01 42.79 42.79 33.69 35.18
2015-02 35.39 35.46 26.61 32.42
2015-03 32.32 37.65 31.93 32.48
...
Any help to solving this question would be highly appreciate.
Best Regards
Gam
There are three places where the first query refers to the specific month searched for. Let's remove the two occurences in the subqueries; this requires using aliases so that we can refer to other instances of the same table by name:
SELECT
strftime ('%Y-%m', dpDate) AS month,
(SELECT dpOpen
FROM DailyPrices
WHERE dpTicker = 'GLE.PA'
AND dpDate =
(SELECT min(dpDate)
FROM DailyPrices AS DP2
WHERE strftime('%Y%m', DP2.dpDate) = strftime('%Y%m', DP1.dpDate)
)
) AS Open,
max(dpHigh) AS High,
min (dpLow) AS Low,
(SELECT dpClose
FROM DailyPrices
WHERE dpTicker = 'GLE.PA'
AND dpDate =
(SELECT max(dpDate)
FROM DailyPrices AS DP2
WHERE strftime('%Y%m', DP2.dpDate) = strftime('%Y%m', DP1.dpDate)
)
) AS Close
FROM DailyPrices AS DP1
WHERE dpTicker ='GLE.PA'
AND strftime('%Y%m', dpDate) = '201509';
Now that only the outermost query needs to know the month, we can simply replace the filter with GROUP BY:
SELECT
strftime ('%Y-%m', dpDate) AS month,
(...) AS Open,
max(dpHigh) AS High,
min (dpLow) AS Low,
(...) AS Close
FROM DailyPrices
WHERE dpTicker ='GLE.PA'
GROUP BY strftime('%Y%m', dpDate);
Please note that the open/close subquery can be simplified by using ORDER BY/LIMIT:
(SELECT dpOpen
FROM DailyPrices
WHERE dpTicker = 'GLE.PA'
AND ... dpDate ...
ORDER BY dpDate ASC
LIMIT 1) AS Open
Thanks CL!! This is good learning for a SQLite newbie, especially for the use of ALIASES.
Your suggestions produce generally good results, however, when running a couple of test runs I noticed occasional errors of the following style:
bash-3.2$ sqlite3 myShares < tst.sql
month Open High Low Close
---------- ---------- ---------- ---------- ----------
2006-03 75.4675 76.5852 70.4136 74.4956
2006-04 75.0787 75.9048 70.5108 72.7948
2006-05 77.0225 68.5184 70.7538
2006-06 70.5594 73.4751 64.7767 72.7462
2006-07 72.5518 75.2245 68.2269 74.0582
bash-3.2$
As you can notice, the Open price for the month of May 2006 is missing. I verified that the data actually exists:
bash-3.2$ sqlite3 myShares < test.sql
dpTicker dpDate dpOpen dpHigh dpLow dpClose dpVolume dpAdjClose dpCreated dpModified
---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------------------- -------------------
BNP.PA 2006-04-26 72.0173 73.1835 72.0173 72.892 2623400 48.8861 2015-12-08 12:04:22 2015-12-08 12:04:22
BNP.PA 2006-04-27 73.8153 74.0096 72.5032 73.6209 6001400 49.375 2015-12-08 12:04:22 2015-12-08 12:04:22
BNP.PA 2006-04-28 73.4751 73.9611 72.6976 72.7948 4133300 48.8209 2015-12-08 12:04:22 2015-12-08 12:04:22
BNP.PA 2006-05-02 72.5518 73.5723 72.3574 73.2807 3085400 49.1468 2015-12-08 12:04:22 2015-12-08 12:04:22
BNP.PA 2006-05-03 73.8639 74.0096 72.5518 72.649 3290400 48.7231 2015-12-08 12:04:22 2015-12-08 12:04:22
BNP.PA 2006-05-04 72.892 73.5237 72.2602 73.3779 3640300 49.212 2015-12-08 12:04:22 2015-12-08 12:04:22
BNP.PA 2006-05-05 73.6209 74.8357 73.4751 74.7872 3255600 50.1572 2015-12-08 12:04:22 2015-12-08 12:04:22
bash-3.2$
For each of the tickers in the SQLite database, I have typically around 4 of those errors over a 16 year period.
As far as my SQLite newbie knowledge reaches, the data in the table is fine.
Any idea why occasionally, the query jumps a summary record? Generally, the descrepancy occurs on the Open Price, but from time to time also on the Close price.
Best regards,
GAM
For the record, the following is the query I have executed
SELECT
strftime ('%Y-%m', dpDate) AS month,
(SELECT dpOpen
FROM DailyPrices
WHERE dpTicker = 'BNP.PA'
AND dpDate =
(SELECT min(dpDate)
FROM DailyPrices AS DP2
WHERE strftime('%Y%m', DP2.dpDate) = strftime('%Y%m', DP1.dpDate)
)
ORDER BY dpDate ASC
LIMIT 1) AS Open,
max(dpHigh) AS High,
min (dpLow) AS Low,
(SELECT dpClose
FROM DailyPrices
WHERE dpTicker = 'BNP.PA'
AND dpDate =
(SELECT max(dpDate)
FROM DailyPrices AS DP2
WHERE strftime('%Y%m', DP2.dpDate) = strftime('%Y%m', DP1.dpDate)
)
) AS Close
FROM DailyPrices AS DP1
WHERE dpTicker ='BNP.PA'
AND strftime('%Y-%m', dpDate) > '2006-02'
AND strftime('%Y-%m', dpDate) < '2006-08'
GROUP BY strftime('%Y-%m', dpDate);
Related
I've got a table in an SQLite3 database containing account balances, but it currently only contains balances for a few specific dates:
Balance Date
Amount
2021-12-15
400
2021-12-18
500
2021-12-22
200
I need to fill in the gaps between these dates with the previous recorded balance, so e.g. 2021-12-16 and 2021-12-17 should have a balance of 400 and 2021-12-19, 2021-12-20 and 2021-12-21 should have a balance of 500.
Is there a way to fill these gaps using SQL? I think I need some logic like
INSERT INTO BALANCES (BalanceDate,BalanceAmount)
VALUES(previous record + 1 day, previous record's amount)
but I don't know how I can point SQL to the previous record.
Thanks
You can use a recursive cte to produce the missing dates:
WITH cte AS (
SELECT date(b1.BalanceDate, '+1 day') BalanceDate, b1.Amount
FROM BALANCES b1
WHERE NOT EXISTS (SELECT 1 FROM BALANCES b2 WHERE b2.BalanceDate = date(b1.BalanceDate, '+1 day'))
AND date(b1.BalanceDate, '+1 day') < (SELECT MAX(BalanceDate) FROM BALANCES)
UNION ALL
SELECT date(c.BalanceDate, '+1 day'), c.Amount
FROM cte c
WHERE NOT EXISTS (SELECT 1 FROM BALANCES b WHERE b.BalanceDate = date(c.BalanceDate, '+1 day'))
AND date(c.BalanceDate, '+1 day') < (SELECT MAX(BalanceDate) FROM BALANCES)
)
INSERT INTO BALANCES(BalanceDate, Amount)
SELECT BalanceDate, Amount FROM cte;
See the demo.
I have a SQLite database with a counter and timestamp in unixtime as showed below:
+---------+------------+
| counter | timestamp |
+---------+------------+
| | 1582933500 |
| 1 | |
+---------+------------+
| 2 | 1582933800 |
+---------+------------+
| ... | ... |
+---------+------------+
I would like to calculate how 'counter' has increased in current day and current week.
It is possible in a SQLite query?
Thanks!
Provided you have SQLite version >= 3.25.0 the SQLite window functions will help you achieve this.
Using the LAG function to retrieve the value from the previous record - if there is none (which will be the case for the first row) a default value is provided, that is same as current row.
For the purpose of demonstration this code:
SELECT counter, timestamp,
LAG (timestamp, 1, timestamp) OVER (ORDER BY counter) AS previous_timestamp,
(timestamp - LAG (timestamp, 1, timestamp) OVER (ORDER BY counter)) AS diff
FROM your_table
ORDER BY counter ASC
will give this result:
1 1582933500 1582933500 0
2 1582933800 1582933500 300
In a CTE get the min and max timestamp for each day and join it twice to the table:
with cte as (
select date(timestamp, 'unixepoch', 'localtime') day,
min(timestamp) mindate, max(timestamp) maxdate
from tablename
group by day
)
select c.day, t2.counter - t1.counter difference
from cte c
inner join tablename t1 on t1.timestamp = c.mindate
inner join tablename t2 on t2.timestamp = c.maxdate;
With similar code get the results for each week:
with cte as (
select strftime('%W', date(timestamp, 'unixepoch', 'localtime')) week,
min(timestamp) mindate, max(timestamp) maxdate
from tablename
group by week
)
select c.week, t2.counter - t1.counter difference
from cte c
inner join tablename t1 on t1.timestamp = c.mindate
inner join tablename t2 on t2.timestamp = c.maxdate;
I have a calendar query and a table below. I have a StartDate and end date for a member. Also on my calendar table I have captured a "Weekof" based on the startDate. I would like to capture if a member is active anytime during that weekof. See expected results.
SELECT DISTINCT
--CA.CALENDAR_DATE,
TO_CHAR(CALENDAR_DATE,'MM/DD/YYYY') AS CALENDAR_DATE
TO_CHAR(NEXT_DAY(CALENDAR_DATE, 'Monday') - 7, 'MM/DD/YY-') ||
TO_CHAR(NEXT_DAY(CALENDAR_DATE, 'Monday') - 1, 'MM/DD/YY') AS WEEK_OF_YEAR,
ROW_NUMBER () OVER ( ORDER BY CALENDAR_DATE) AS MasterCalendar_RNK
FROM CALENDAR CA
WHERE 1=1
--AND CA.CALENDAR_DATE BETWEEN ADD_MONTHS(TRUNC(SYSDATE), -12) AND TRUNC(SYSDATE)
--AND CA.CALENDAR_DATE BETWEEN TRUNC(SYSDATE) -5 AND TRUNC(SYSDATE)
ORDER BY TO_DATE(CALENDAR_DATE,'MM/DD/YYYY') DESC
Table
Member StartDate EndDate
A 1/31/17
B 2/1/17 2/15/17
Expected output:
Member StartDate EndDate Week_Of_Year Active
A 1/31/17 1/30/17-2/5/17 1
A 1/31/17 2/6/17-2/12/17 1
A 1/31/17 2/13/17-2/19/17 1
B 2/1/17 2/15/17 1/30/17/2/5/17 1
B 2/1/17 2/15/17 2/6/17-2/12/17 1
B 2/1/17 2/15/17 2/13/17-2/19/17 1
Current Query:
WITH MASTER_CALENDAR AS (
SELECT TRUNC(SYSDATE) + 1 - LEVEL , A.CALENDAR_DATE
FROM (SELECT C.CALENDAR_DATE FROM MST.CALENDAR C WHERE 1=1 AND C.CALENDAR_DATE > SYSDATE-30 AND C.CALENDAR_DATE < SYSDATE) A
WHERE 1=1
CONNECT BY LEVEL <= 1 --NEED TO UPDATE?
ORDER BY A.CALENDAR_DATE DESC
),
ActiveMembers AS (
SELECT H.CLT_CLT_PGMID, H.START_DT
,CASE WHEN TRUNC(H.END_DT) = '1-JAN-3000'
THEN SYSDATE
ELSE TO_DATE(H.END_DT)
END AS END_DT
FROM H
WHERE 1=1
AND H.CLT_CLT_PGMID IN ('1','2','3')
)
SELECT CLT_CLT_PGMID, STARTDATE, ENDDATE, WEEK_OF_YEAR, ACTIVE -- but not week_start
FROM (
SELECT DISTINCT A.CLT_CLT_PGMID,
TO_CHAR(A.START_DT, 'MM/DD/YY') AS STARTDATE,
TO_CHAR(A.END_DT, 'MM/DD/YY') AS ENDDATE,
NEXT_DAY(CAL.CALENDAR_DATE, 'Monday') - 7 AS WEEK_START, -- for ordering later
TO_CHAR(NEXT_DAY(CAL.CALENDAR_DATE, 'Monday') - 7, 'MM/DD/YY-') ||
TO_CHAR(NEXT_DAY(CAL.CALENDAR_DATE, 'Monday') - 1, 'MM/DD/YY') AS WEEK_OF_YEAR,
1 AS ACTIVE
FROM ActiveMembers A
INNER JOIN MASTER_CALENDAR CAL ON CAL.CALENDAR_DATE BETWEEN A.START_DT AND A.END_DT
--BETWEEN TO_CHAR(A.START_DT,'MM/DD/YYYY') AND COALESCE(A.END_DT,(SYSDATE))
)
WHERE 1=1
ORDER BY
CLT_CLT_PGMID , STARTDATE, ENDDATE, WEEK_START
;
Since the calendar query currently generates strings, it would be simpler to go back to the calendar table, join that to your member/date table, and regenerate the week range string:
With CTEs to represent your calendar table (just with dates for the last few weeks for now) and member data:
with calendar(calendar_date) as (
select trunc(sysdate) + 1 - level from dual connect by level <= 42
),
mytable (member, startdate, enddate) as (
select cast('A' as varchar2(6)), date '2017-01-31', cast (null as date) from dual
union all select cast('B' as varchar2(6)), date '2017-02-01', date '2017-02-15' from dual
)
select member, startdate, enddate, week_of_year, active -- but not week_start
from (
select distinct m.member,
to_char(m.startdate, 'MM/DD/YY') as startdate,
to_char(m.enddate, 'MM/DD/YY') as enddate,
next_day(c.calendar_date, 'Monday') - 7 as week_start, -- for ordering later
to_char(next_day(c.calendar_date, 'Monday') - 7, 'MM/DD/YY-') ||
to_char(next_day(c.calendar_date, 'Monday') - 1, 'MM/DD/YY') as week_of_year,
1 as active
from mytable m
join calendar c
on c.calendar_date between m.startdate and coalesce(m.enddate, trunc(sysdate))
)
order by member, startdate, enddate, week_start;
gets
MEMBER STARTDAT ENDDATE WEEK_OF_YEAR ACTIVE
------ -------- -------- ----------------- ----------
A 01/31/17 01/30/17-02/05/17 1
A 01/31/17 02/06/17-02/12/17 1
A 01/31/17 02/13/17-02/19/17 1
A 01/31/17 02/20/17-02/26/17 1
B 02/01/17 02/15/17 01/30/17-02/05/17 1
B 02/01/17 02/15/17 02/06/17-02/12/17 1
B 02/01/17 02/15/17 02/13/17-02/19/17 1
You haven't specified an upper limit for members with no end-date, so I've used today, via coalesce().
The inner query is only needed for ordering, as the week range string can't be used, and you don't want to see the week start on its own; and you can't use distinct and order by a field you aren't selecting.
I'd do this in a similar way to Alex, but slightly different. Seeing as your weeks start with a Monday, I'd use TRUNC(dt, 'iw') to get the ISO start of the week (which happens to be defined as a Monday) for the specified date. Then I'd get the distinct values of those before joining to your table, like so:
with calendar as (select trunc(sysdate) - level + 1 calendar_date
from dual
connect by level <= 50),
your_table as (select 'A' member, date '2017-01-31' startdate, NULL enddate from dual union all
select 'B' member, date '2017-02-01' startdate, date '2017-02-15' enddate from dual)
select yt.member,
yt.startdate,
yt.enddate,
to_char(c.week_start, 'mm/dd/yyyy')
|| ' - ' || to_char(c.week_start + 6, 'mm/dd/yyyy') week_of_year,
1 as active
from your_table yt
inner join (select distinct trunc(cl.calendar_date, 'iw') week_start
from calendar cl) c on c.week_start <= nvl(yt.enddate, SYSDATE) AND c.week_start + 6 >= yt.startdate
order by yt.member,
c.week_start;
MEMBER STARTDATE ENDDATE WEEK_OF_YEAR ACTIVE
------ ---------- ---------- ----------------------- ----------
A 01/31/2017 01/30/2017 - 02/05/2017 1
A 01/31/2017 02/06/2017 - 02/12/2017 1
A 01/31/2017 02/13/2017 - 02/19/2017 1
A 01/31/2017 02/20/2017 - 02/26/2017 1
B 02/01/2017 02/15/2017 01/30/2017 - 02/05/2017 1
B 02/01/2017 02/15/2017 02/06/2017 - 02/12/2017 1
B 02/01/2017 02/15/2017 02/13/2017 - 02/19/2017 1
Like Alex, I've assumed your null enddate runs up until today (sysdate). However, looking at your results for member B, it looks like you're looking for an overlapping range (since 30th Jan is not between 1st and 15th Feb), so I've amended my join clause accordingly. This results in an extra row for member A, so maybe you're wanting to run null enddates up until the previous Sunday of sysdate? Not sure. I'm sure you'll be able to amend that yourself, if you need to.
I have the following query which I am trying to rewrite:
SELECT
max(dpHigh) AS High
FROM DailyPrices
WHERE dpTicker = 'DL.AS'
AND dpDate IN
(SELECT
dpDate
FROM DailyPrices
WHERE dpTicker ='DL.AS'
ORDER BY update DESC
LIMIT 10);
The query gives me the required result:
bash-3.2$ sqlite3 myData < Queries/high.sql
High
----------
4.67
bash-3.2$
Since next to the high value I wish to expand this query to also obtain a low value, earliest date, latest date, etc. For this reason, I am trying re-write an equivalent query using a select in select statement.
SELECT
(SELECT
max(dpHigh)
FROM DailyPrices
WHERE dpTicker = 'DL.AS'
AND dpDate IN
(SELECT dpDate
FROM DailyPrices
WHERE dpTicker ='DL.AS'
ORDER BY dpDate DESC
LIMIT 10)
)AS High
FROM DailyPrices
WHERE dpTicker = 'DL.AS';
Execution of the query spits output the expected value, however, it does exactly for the number of data entries of 'DL.AS'.
...
4.67
4.67
4.67
4.67
4.67
4.67
4.67
bash-3.2$
Since I am a SQLite newbie, I am probably overlooking the obvious. Does anybody have any suggestions?
BR
GAM
The outermost query looks like this:
SELECT (...)
FROM DailyPrices
WHERE dpTicker = 'DL.AS';
This will generate one output row for each table row with a matching dpTicker.
To generate a single row, regardless of how many rows might be found in some table, use a query without a FROM (the filtering and aggregation is already handled in the subqueries):
SELECT (...) AS High,
(...) AS Low;
I have the following query that provides me with the 10 most recent records in the database:
SELECT
dpDate AS Date,
dpOpen AS Open,
dpHigh AS High,
dpLow AS Low,
dpClose AS Close
FROM DailyPrices
WHERE dpTicker = 'DL.AS'
ORDER BY dpDate DESC
LIMIT 10;
The result of this query is as follows:
bash-3.2$ sqlite3 myData < Queries/dailyprice.sql
Date Open High Low Close
---------- ---------- ---------- ---------- ----------
2016-06-13 4.0 4.009 3.885 3.933
2016-06-10 4.23 4.236 4.05 4.08
2016-06-09 4.375 4.43 4.221 4.231
2016-06-08 4.406 4.474 4.322 4.35
2016-06-07 4.377 4.466 4.369 4.384
2016-06-06 4.327 4.437 4.321 4.353
2016-06-03 4.34 4.428 4.316 4.335
2016-06-02 4.434 4.51 4.403 4.446
2016-06-01 4.51 4.512 4.317 4.399
2016-05-31 4.613 4.67 4.502 4.526
bash-3.2$
Whilst I need to plot the extracted data, I also need to obtain the following summary data of the dataset:
Minimum date ==> 2016-05-31
Maximum date ==> 2016-06-13
Open value at minimum date ==> 4.613
Close value at maximum date ==> 3.933
Maximum of High column ==> 4.67
Minimum of Low column ==> 3.885
How can I, as newbie, approach this issue? Can this be done in one query?
Thanks for pointing me in the right direction.
Best regards,
GAM
The desired output can be achieved with
aggregate functions on a convenient common table expression,
which uses OPs expression verbatim
OPs method, with limit 1 applied to common table expression,
for getting mindate and maxdate among the ten days
Query:
WITH Ten(Date,Open,High,Low,Close) AS
(SELECT dpDate AS Date,
dpOpen AS Open,
dpHigh AS High,
dpLow AS Low,
dpClose AS Close
FROM DailyPrices
WHERE dpTicker = 'DL.AS'
ORDER BY dpDate DESC LIMIT 10)
SELECT min(Date) AS mindate,
max(Date) AS maxdate,
(SELECT Open FROM Ten ORDER BY Date ASC LIMIT 1) AS Open,
max(High) AS High,
min(Low) AS Low,
(SELECT Close FROM Ten ORDER BY Date DESC LIMIT 1) AS Close
FROM Ten;
Output (.headers on and .mode column):
mindate maxdate Open High Low Close
---------- ---------- ---------- ---------- ---------- ----------
2016-05-31 2016-06-13 4.613 4.67 3.885 3.933
Note:
I think the order of values in OPs last comment do not match the order of columns in the preceding comment by OP.
I chose the order from the preceding comment.
The order in the last comment seems to me to be "mindate, maxdate, Open, Close, High, Low".
Adapting my proposed query to that order would be simple.
Using SQLite 3.18.0 2017-03-28 18:48:43
Here is the .dump of my toy database, i.e. my MCVE, in case something is unclear. (I did not enter the many decimal places, it is probably a float rounding thing.)
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE dailyPrices (dpDate date, dpOpen float, dpHigh float, dpLow float, dpClose float, dpTicker varchar(10));
INSERT INTO dailyPrices(dpDate,dpOpen,dpHigh,dpLow,dpClose,dpTicker) VALUES('2016-06-13',4.0,4.009000000000000341,3.8849999999999997868,3.9329999999999998294,'DL.AS');
INSERT INTO dailyPrices(dpDate,dpOpen,dpHigh,dpLow,dpClose,dpTicker) VALUES('2016-06-10',4.2300000000000004263,4.2359999999999997655,4.0499999999999998223,4.080000000000000071,'DL.AS');
INSERT INTO dailyPrices(dpDate,dpOpen,dpHigh,dpLow,dpClose,dpTicker) VALUES('2016-06-09',4.375,4.4299999999999997157,4.2210000000000000852,4.2309999999999998721,'DL.AS');
INSERT INTO dailyPrices(dpDate,dpOpen,dpHigh,dpLow,dpClose,dpTicker) VALUES('2016-06-08',4.4059999999999996944,4.4740000000000001989,4.3220000000000000639,4.3499999999999996447,'DL.AS');
INSERT INTO dailyPrices(dpDate,dpOpen,dpHigh,dpLow,dpClose,dpTicker) VALUES('2016-06-07',4.3769999999999997797,4.4660000000000001918,4.3689999999999997726,4.384000000000000341,'DL.AS');
INSERT INTO dailyPrices(dpDate,dpOpen,dpHigh,dpLow,dpClose,dpTicker) VALUES('2016-06-06',4.3269999999999999573,4.4370000000000002771,4.3209999999999997299,4.3529999999999997584,'DL.AS');
INSERT INTO dailyPrices(dpDate,dpOpen,dpHigh,dpLow,dpClose,dpTicker) VALUES('2016-06-03',4.3399999999999998578,4.4370000000000002771,4.3209999999999997299,4.3529999999999997584,'DL.AS');
INSERT INTO dailyPrices(dpDate,dpOpen,dpHigh,dpLow,dpClose,dpTicker) VALUES('2016-06-02',4.4340000000000001634,4.5099999999999997868,4.4029999999999995807,4.4459999999999997299,'DL.AS');
INSERT INTO dailyPrices(dpDate,dpOpen,dpHigh,dpLow,dpClose,dpTicker) VALUES('2016-06-01',4.5099999999999997868,4.5119999999999995665,4.3170000000000001705,4.3990000000000000213,'DL.AS');
INSERT INTO dailyPrices(dpDate,dpOpen,dpHigh,dpLow,dpClose,dpTicker) VALUES('2016-05-31',4.6130000000000004334,4.6699999999999999289,4.5019999999999997797,4.525999999999999801,'DL.AS');
COMMIT;