How to combine a where Statement to find the Highest Value over a specific time interval [closed] - sql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 12 hours ago.
Improve this question
I have a SQL query where I am trying to find the highest of stock over a given period. One of those periods is the Overnight Night High. The futures market overnight session is from 17:00 - 08:30 CST. This time crosses two date periods.
I want to know how I can format a query where it will only look for the highest price across a period of 2 dates but, getting the highest price between the hours of 1700 - 08:30 overnight. For example, Futures would open at 17:00 on 2/6/2023 and the overnight session would cease at 08:30 on 2/7/2023. The current query I have does not know how to separate dates it finds the highest price between the periods of 17:00 - 23:55 and 00:00-08:30 am of that same date. I have the datatype set as text variable for the Date and Time columns. The first picture shows the database head as a whole from the CSV. The next shows the query I currently have. Head of database
Current Query
Output
The output should match these numbers and return a result from days 2/6-2/10 Instead the results do not know how to separate days and return the Hi and lo price from 2/5-2/10
Current results

Related

SUM HH.MM.SS IN SQL OR AS400 DATABASE [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to calculate total working hour from the table field as below:
table name : Attendance
field name : working_hours
select SUM(working_hours) from Attendance
In working_hours field i have data in format
empcode working_hours
123456 08.45.00
123456 10.06.00
123456 10.00.00
123456 09.06.00
I want this in Total hours like (17.50.00)
Thanks in advance.
the hour and minute sql functions will return the hour and minutes of the working_hours time field. You can sum up hours and minutes. Then divide total minutes by 60 to get the hours the minutes add up to. And the mod function returns the remainder of minutes divided by 60.
select sum(hour(a.working_hours)) +
sum(minute(a.working_hours)) / 60 ,
mod(minute(a.working_hours),60)
from attendance a

Access SQL Issue [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am curious if there are any experts in Access' version of SQL that could help me decode the below? I am not great in Access and try use SSMS but I am taking over an already built report.
Thanks!
LT CRD: IIf(Day(Date()+[IAM_MAN_LEAD_TIME]) Between 1 And 15,DateSerial(Year(Date()+[IAM_MAN_LEAD_TIME]),Month(Date()+[IAM_MAN_LEAD_TIME]),15),DateSerial(Year(Date()+[IAM_MAN_LEAD_TIME]),Month(Date()+[IAM_MAN_LEAD_TIME])+1,0))
In words, the code is saying
"If the current date + [IAM_MAN_LEAD_TIME] results in a date in the first 15 days of a month, then return the 15th of that month; else, return the date of the last day of the month."
For reference -
Date() returns the current date
Day() returns the day part of a date, e.g. Day(#2018-10-29#) = 29
DateSerial() returns a date given a year, month & day argument.
Year() returns the year part of a date, e.g. Year(#2018-10-29#) = 2018
Month() returns the month part of a date, e.g. Month(#2018-10-29#) = 10
Also note that DateSerial(Year, Month, 0) will return the last day in the previous month i.e. the day before DateSerial(Year, Month, 1)

Calculate number of days from date represented as integer [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a column (EOM) in my table(Employee) which gives the last day of the month as an integer and I want to return the number of days in the month. I know we can normally use the built-in functions but since the DATE that I have is stored as an int they won't work. Can anyone help me out with this?
EmpID EmployeeName EOM
123 ABC 20160731
345 XYZ 20150228
I want to know the number of days that say Employee ABC worked for which is 31.
If you have the last day of the month in EOM column then you can simply take the last 2 characters from EOM column, which will give you number of days in the month.
SELECT SUBSTRING(EOM,7,2) FROM EMPLOYEE
OR
SELECT CONVERT(INT,SUBSTRING(EOM,7,2)) FROM EMPLOYEE
This will give you the number which you can work with to get the number of days Employee worked for.

Get Missing Month [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have result set like
DT_START DT_END
------------- -----------
2013-05-01 2014-04-01
2014-07-01 2015-04-01
2014-11-01 2015-02-01
i have start date and end date.i need missing month of 2014 in both dates.
Like missing month in 2014 is 5 and 6 (it is the difference between first row "DT_END" and second row "DT_START")
One possible solution:
Create a calendar table or make a query that returns all the months between the lowest dt_start and the highest dt_end. How you do this will depend on the actual database you use - some have nice functions that you can use to create sequences, some have number tables etc.
Then use that as source and do a left join with your table and filter out the rows where dt_start is null.
select month from all_months -- this is the table/query with all months
left join your_table on month between dt_start and dt_end
where dt_start is null

Return employee's who were hired in first half of the month [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How can I return the employee names from table hr.employees who were hired on first half of the month, i.e. with a date of 1st to 15th of that month.
SELECT
*
FROM
Employee e
WHERE
TO_NUMBER(TO_CHAR(e.DateHired, 'DD')) <= 15
Technically, the 15th isn't the first half of the month. It might be the 14th.
To get the first half you would have to work out the maximum number of days in the month, then divide by 2, round down or up (I'd always round down) to get the number of days into the month you need to select from.
Then you need to add this number to the beginning of the month and minus one as the month starts on the first.
You also need to restrict to ensure that you're looking at the same month.
select *
from employee
where trunc(datehired) <= trunc(sysdate, 'mm')
+ floor(to_number(to_char(last_day(sysdate),'DD'))/2)
- 1
and trunc(datehired,'mm') = trunc(sysdate, 'mm')