SQL does not show me the time (hour by day) - oracle11g

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;

Related

defining business day where hours are not same as standard days

While working on a sales report for an entertainment company ( bars and nightclubs), I normally just sum sales and I get the daily sum of sales. but I was communicated that their business day starts at 6 am of each and closes at 5:59:59 am the next day. basically sales reported Monday are the sales from 6 am Sunday thru 5:59:59 am Monday.
the company operates throughout the US so we have multiple time zones as well
the table has the following columns:
Transaction id, location, Transaction_datetimeLocal, TransactionDateTimeUTC, Transaction amount
how do I define / filter the calculation to be from 6am one day to 5:59:59 am the next day USING Power BI / DAX
TIA
In Power BI you have your table with the local time. You need to add a calculated column with the following DAX formula:
Business Time = 'Table'[Local Time] - TIME(6, 0, 0)
From this new column you could the create your business date with
Business Date = 'Table'[Business Time].[Date]
This is how it looks in the Data view:

How to pull data from the past 3 days, not including today's and yesterday's from Bigquery

Using standars SQL. When the table consists of wildcard tables.
I Try to use this:
SELECT *
FROM `Resourse.Reports_Reg.Session_streaming`
WHERE
SUBSTR(_table_suffix, 0, 6) =
FORMAT_DATE("%E4Y%m", DATE_SUB(CURRENT_DATE, INTERVAL 3 day))
This request, I thought, should return data for the last 5 days. But I still do not understand what data it returns to me. How to pull data from the past 3 days, not including today's and yesterday's
As it is, you are not selecting anything into _table_suffix given that your query has no wildcard.
If your table have for instance a name structure like:
`Resourse.Reports_Reg.Session_streaming_20170820`
where the very last string is a date with format "%Y%m%d", then selecting past third and second days can be done like:
SELECT
*
FROM `Resourse.Reports_Reg.Session_streaming_*`
WHERE _TABLE_SUFFIX BETWEEN FORMAT_DATE("%Y%m%d", DATE_SUB(CURRENT_DATE, INTERVAL 3 day)) AND FORMAT_DATE("%Y%m%d", DATE_SUB(CURRENT_DATE, INTERVAL 2 day))
Notice the wildcard "*" is selecting the date "20170820" for instance. After that, there's just a where clause selecting appropriate dates.

Apache Drill: Group by week

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

Empty result in association parent-children when there are not children

I have the following schema:
hours table: this table has "constant" data, it never changes because only will store the schedule-able hours
hour (int)
----
8
9
10
appointments table
hour (int) | date (text)
--------------------------
10 | 25/08/2015
In my application I want to show only available hours to set a new appointment based in hour-date filter. For example, I can say that for the days:
25/08/2015: available hours are 8 and 9 because 10 is already taken
26/08/2015: available hours are 8, 9 and 10 because there are not appointments at that date.
At the beginning I was using this query:
select h.hour
from hours h, appointment a
where h.hour != a.hour and a.date = 'the-date';
This query only works if there are appointments in the given dates, but for the rest of dates without appointments it returns empty result. I can achieve this task via application, but I am trying to exhaust all db's possibilities.
You could use an outer join, but a subquery might be easier to understand:
SELECT hour
FROM hours
WHERE hour NOT IN (SELECT hour
FROM appointment
WHERE date = ?)

Update only the year in SQLite column

I have a SQLite3 database that has 366 rows in it, and a date for each day of the year. I need to make sure that the year is current, and if it is not, then I need to update the year to the current calendar year. What I would like to do is something like the following:
UPDATE daily SET date = DATE('%Y', 'now');
or
UPDATE daily SET date = strftime('%Y', 'now');
But those queries just make the date column NULL, and even if they did work as I expected them to, I doubt that it would retain the day and month that is there already.
In MySQL, I can do something like UPDATE daily SET date = ADDDATE(date, INTERVAL 1 YEAR) -- but firstly, it is not a valid SQLite query, and secondly, I need to update to the current year, not just step up one year.
Any help would be appreciated.
Try this:
create table t (id int, d text);
insert into t
select 1, date('2011-01-01') union
select 2, date('2012-03-11') union
select 3, date('2013-05-21') union
select 4, date('2014-07-01') union
select 5, date('2015-11-11');
select * from t;
update t set
d = date(strftime('%Y', date('now')) || strftime('-%m-%d', d));
select * from t;
It uses Date And Time Functions. Firstly it takes month and day from field (strftime('-%m-%d', d)) then add (concatenate) current year (strftime('%Y', date('now'))) and converts it to date.
SQL Fiddle live example.

Resources