I want group by the result data of oracle database. And also I got the result but the result is groupped as month start to next month start.
I need group by from month start to month end.
"GROUP BY TO_CHAR(COL_DATE,'MON-YYYY')"
As I am getting data from 01-Feb-2018 to 01-Mar-2018.
Required data from 01-Feb-2018 to 28-Feb-2018.
use the TRUNC function.
the following example shows the number of entries per month
SELECT TRUNC(COL_DATE, 'MONTH') AS MONTH, COUNT(*)
FROM TABLE
GROUP BY TRUNC(COL_DATE, 'MONTH');
Related
I'm looking for a good solution to show the average temperature day by day of the year from a SQLite Database.
In my database, to be sample, I have a date column and a temp column, for each day since 5 years like that.
example
I would like to get, for each day of the year, the average temperature from my database.
I found the request to calculate the average for one day, but I don't how can I do like that for each day
SELECT avg(min) FROM historique WHERE strftime('%m-%d', date )= "04-01";
Could you help me please ?
You must use use GROUP BY:
SELECT strftime('%m-%d', date) day, avg(min)
FROM historique
GROUP BY day
SQL does not show me the time, I have a business day table, and I need that for each business day it shows me a time range from 9 to 19 hours to then show the number of transactions per hour, for each day of the month.
I can not generate stored procedure only query can be performed not to alter the database by company policy
I have a query like that.
SELECT
TO_CHAR(cd.days, 'yyyymmdd') AS fechaTransaccion,
NVL(SUM(data.numTransacionExitosa),0) AS numTransacionExitosa,
NVL(SUM(data.numTransactionPendiente),0) AS numTransactionPendiente
FROM
calendardays cd
LEFT JOIN
data
ON
cd.days = data.settledate
WHERE
cd.DAYs BETWEEN ADD_MONTHS(TRUNC(to_date(20200201, 'yyyymmdd'), 'MM'),-1) AND ADD_MONTHS(LAST_DAY(TRUNC(to_date(20200201, 'yyyymmdd'))),-1)
and substr(SETTLEDATE, 10, 2) between 9 and 19
GROUP BY
cd.days, substr(SETTLEDATE, 10, 2)
ORDER BY
cd.days
i need show like this
Hard to understand/answer without seeing your data, but if you need to extract hour from date, follow the below example:
select extract(hour from cast(sysdate as timestamp)) hour from dual;
I have an actual bigquery table with a datetime column, and i want to split this datetime in other columns such as : year, month, day, quarter
I have succeeded the extract with the query :
SELECT
date,
EXTRACT(YEAR FROM date) as year,
EXTRACT(MONTH FROM date) as month,
EXTRACT(QUARTER FROM date) as quarter
FROM
'project.dataset.table'
;
How to get the result and update the table by creating the new year/month/quarter columns ?
I tried the method : SET year = EXTRACT(YEAR FROM date) WHERE TRUE
but it didn't work
you need to use the query in the scope of a DML UPDATE statement https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#update_statement
I have a table consisting of a date field and a barcode field; I want the number of barcodes grouped by day for the previous month.
This looked like it would work:
SELECT
COUNT(*) AS count,
strftime('%d-%m-%Y',date) AS day
FROM barcodes
WHERE date >= datetime('now', '-1 month')
GROUP BY day
ORDER BY date ASC;
But that gives me incorrect counts. E.g.:
341|30-01-2017
274|31-01-2017
288|01-02-2017
332|02-02-2017
224|03-02-2017
35|04-02-2017
1009|06-02-2017
1481|07-02-2017
1626|08-02-2017
507|09-02-2017
428|10-02-2017
125|11-02-2017
1838|13-02-2017
2591|
Whereas:
SELECT COUNT(*) FROM barcodes WHERE date LIKE '2017-02-10%';
579
If I do this:
SELECT
COUNT(*) AS count,
strftime('%d-%m-%Y',date) AS day
FROM barcodes
WHERE date LIKE '2017-02-10%'
GROUP BY day
ORDER BY date ASC;
I get:
428|10-02-2017
151|
So my question is: why is SQLite providing the result as two lines when I use strftime()?
%d-%m-%Y is not one of the supported date formats, so comparisons do not work correctly, and any of the built-in date functions will return NULL.
I tried to group my daily data by week (given a reference date) to generate a smaller panel data set.
I used postgres before and there it was quite easy:
CREATE TABLE videos_weekly AS SELECT channel_id,
CEIL(DATE_PART('day', observation_date - '2016-02-10')/7) AS week
FROM videos GROUP BY channel_id, week;
But it seems like it is not possible to subtract a timestamp with a date string in Drill. I found the AGE function, which returns an interval between two dates, but how to convert this into an integer (number of days or weeks)?
DATE_SUB may help you here. Following is an example:
SELECT extract(day from date_sub('2016-11-13', cast('2015-01-01' as timestamp)))/7 FROM (VALUES(1));
This will return number of weeks between 2015-01-01 and 2016-11-13.
Click here for documentation