SUM HH.MM.SS IN SQL OR AS400 DATABASE [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 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

Related

How to combine a where Statement to find the Highest Value over a specific time interval [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 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

Max Date Minus X Days [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 have a date in the database.
I have to choose the maximum date and subtract x days from it.
it should happen according to the expression below I have selected a maximum date but I have to subtract certain days from date
DECLARE #MAX_DATE_VB as datetime
SET #MAX_DATE_VB = (SELECT MAX(CONVERT(DATE, Date_of_drop)) as MAX_DATE
FROM STORAGE
the desired result is to select the maximum date that is in the database but munis x days
I think you are looking for the dateadd function:
select dateadd(dd, -1, #max_date_vb) as new_date
You may change the second argument for the specific days you need to subtract.
See documentation for usage: https://learn.microsoft.com/en-us/sql/t-sql/functions/dateadd-transact-sql?view=sql-server-ver15

SQL how we can count without while loop [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 2 years ago.
Improve this question
I want to count frequency rate of stop work hours from 01-01-2020 to the current day ,
I have a table event contain harret column = hours of stop working and a table of employe .
the frequency rate calculation formula is
number of hours of stoppage * 1,000,000 / number of hours worked * number of employees
select SUM (harret) * 1000000 / datedif from event,
select (((cast(now() as date) - '2020-01-01') * 11 )/7 ) * count(*) as datedif from employe
I think the logic you want is:
select sum(case when extract(isodow from dt) <= 5 then 7.6 else 4 end) as total_working_hours
from generate_series(date '2020-01-01', current_date, '1 day') d(dt)
generate_series() produces one row per day since the beginning of the year. Then we compute the working hours, as 7.6 hours per week day and 4 hours per week-end day.

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 dates between current date and a given month in postgresql [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a table named Stock which contains the records of medicine stocks. It has a column named expDate. I want to select the stocks which are about to expire between the current date (current month) and a given month
Ex: select stocks which has the expDate between 4 months from today/this month
I know that I have to write a query for this and I know how to get records between two dates. But I don't know to write a query to get records between current date and 4 months from the current date.
How can I do that ?
I would use something like this:
dbname=> create table stock ( medicine character varying ( 32 ), expDate timestamp );
CREATE TABLE
dbname=> insert into stock values ( 'first', '2015-01-01'), ('second', '2016-01-01');
INSERT 0 2
dbname=> select * from stock where expDate < now() + '4 months';
medicine | expdate
----------+---------------------
first | 2015-01-01 00:00:00
(1 row)
The now() gives the current timestamp, the + '4 months' adds an interval of 4 months.