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 = ?)
Related
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 a table in Smartsheets that has bookings in it.
If the appointment is confirmed it changes the status to scheduled. It also has a date assigned to it. I'm trying to use countifs to see how many are scheduled for the next 7 days.
This is the formula i have.
=COUNTIFS([Shoot Setup]:[Shoot Setup], "Styleshoots", [Date start]:[Date
start], >=TODAY(7))
This does not give me the correct value.
If i dont have the 7 modifier then it gives me the correct value for items scheduled from today.
But i want to just see the total for today plus 6 days 7 days in total.
Any suggestions?
The formula you've posted will return the count of rows where:
Shoot Setup = "Styleshoots"
AND
Date start is greater than or equal to seven days from today
Try using this formula instead:
=COUNTIFS([Shoot Setup]:[Shoot Setup], "Styleshoots", [Date start]:[Date start], >=TODAY(), [Date start]:[Date start], <=TODAY(7))
This formula will return the count of rows where:
Shoot Setup = "Styleshoots"
AND
Date start is greater than or equal to Today
AND
Date start is less than or equal to 7 days from today
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.
I'm trying to grasp the recently added group by in Riak TS.
I'm unable to find a way to group my results by minute, e.g. count. I'll show an example below.
CREATE TABLE Results
(
result VARCHAR NOT NULL,
time TIMESTAMP NOT NULL,
PRIMARY KEY (
(QUANTUM(time, 1, 'm')),
time
)
)
Inserts
INSERT INTO FreightMinuteResult VALUES ('Novo', '2017-12-07 12:03:45Z');
INSERT INTO FreightMinuteResult VALUES ('Novo', '2017-12-07 12:04:45Z');
INSERT INTO FreightMinuteResult VALUES ('Novo', '2017-12-07 12:05:45Z');
INSERT INTO FreightMinuteResult VALUES ('Novo', '2017-12-07 12:05:46Z');
Query
select count(*) from FreightMinuteResult where time > '2017-12-07 12:01:00Z' and time < '2017-12-07 12:06:00Z' group by time;
The result is
+--------+--------------------+
|COUNT(*)| time |
+--------+--------------------+
| 1 |2017-12-07T12:04:45Z|
| 1 |2017-12-07T12:03:45Z|
| 1 |2017-12-07T12:05:45Z|
| 1 |2017-12-07T12:05:46Z|
+--------+--------------------+
How to count the number of occurrences per minute using Riak TS?
Thanks.
The quantum is used to organize the data in the backend to streamline query operations, while group by uses the exact value of the specified field. The timestamps 2017-12-07T12:05:45Z and 2017-12-07T12:05:46Z occur in the same minute and will therefore be stored in the same location on disk, but they are still stored as distinct second-resolution timestamp values that will be grouped separately.
If you want to be able to group by the minute you will need to either round the timestamps when inserting, or modify your table to include a minute field that can be grouped.
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