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 have a table with following structure
ID newSatus modifiedDate
252123_001 Closed 2020-10-07 20:14:57.477
252123_001 Shipped 2020-10-07 09:24:12.693
252309_001 Closed 2020-10-08 18:51:34.810
252309_001 Shipped 2020-10-07 09:22:33.537
252404_001 Closed 2020-10-07 12:25:10.270
252404_001 Shipped 2020-10-07 09:29:02.363
Basically what i would like to do is have an access query that calculates the date difference for consecutive records between different newStatus but for the same ID.
The expected result would be !!
ID diffHours diffMinutes diffSeconds
252123_001 10h:50m:45s 650 39045
252309_001 1 day 9h:29m:01s 2009 120541
252404_001 2h:56m:08s 176 10568
And finally calculates de median of time between these results.
You want to aggregate your rows so as to get one result row per ID. "Per ID" translates to GROUP BY id in SQL.
select
id,
datediff ("h", min(modifieddate), max(modifieddate)) as diff_hours,
datediff ("n", min(modifieddate), max(modifieddate)) as diff_minuts,
datediff ("s", min(modifieddate), max(modifieddate)) as diff_seconds
from mytable
group by id
order by id;
I must admit that I don't know how to get the median from this in MS Access, as this is the RDBMS farthest from the SQL standard that I know of.
Can you try to ungroup the data so that you have seperate column for status Closed and Shipped? The you can use simple subtraction to get the difference in time, and from that you can calculate all the things you mentioned.
Related
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 2 years ago.
Improve this question
I need to transform the table below to give me a list of the periods with a close date, and the close date from the previous period. This will give me a date range for that period so that it look like the following:
NOV20 | 2020-12-10 | 2020-11-11
DEC20 | 2021-01-15 | 2020-12-10
Thanks
You seem to want to bring the preceding close date in each row. If so, use lag():
select id, period, closedate,
lag(closedate) over(order by closedate) last_closedate
from mytable
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 3 years ago.
Improve this question
I need to get one row per person per month and that row should be maximum date in that month.
Data available:
person date value
a jan/1/2019 10
a jan/2/2019 20
a feb/3/2019 30
b jan/10/2019 20
b jan/20/2019 30
b feb/1/2019 40
b feb/12/2019 30
Desired output:
a jan/2/2019 20
a feb/3/2019 30
b jan/20/2019 30
b feb/12/2019 30
I am not able to figure out how to achieve this. Any help is highly appreciated.
You can use an aggregation within the subquery and connect them by in operator :
select *
from tab
where (person,date) in
(
select person,max(date)
from tab
group by person,month(date),year(date)
)
Demo
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 have below database table,In here i need group some data and get sum and avg of some data.
In here i need to calculate Item marketers monthly sales(Each Month)
As a Example :
I need to get a Patric Newton's Sales in Each months.
And also i need to calculate AvarageFactor of each month Each employee.
AvgFactor = SUM(Daily Sales)/ SUM(Value Factor) * 100( Each Month )
Database Table
I have tried it like below,
SELECT ItemMarketerName,DailySales,ValueFactor,[Month],[Year]
FROM [SR_Hotel].[dbo].[Table_1]
WHERE ItemMarketerName IS NOT NULL
Group by ItemMarketerName,DailySales,ValueFactor,[Month],[Year]
Order by ItemMarketerName
You should not include your aggregated columns in your GROUP BY.
Try:
SELECT ItemMarketerName, [Month], [Year], SUM(DailySales), SUM(DailySales) / SUM(ValueFactor) * 100
FROM [SR_Hotel].[dbo].[Table_1]
WHERE ItemMarketerName IS NOT NULL
GROUP BY ItemMarketerName, [Month], [Year]
ORDER BY ItemMarketerName
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 5 years ago.
Improve this question
It's a pretty basic sql statement I imagine, but I can't for the life of me figure out how to do.
So I have a table where I have three columns : Amount of car sold (AOCS), Day of the week (DOTW), Previous day of the week (PDOTW).
I'd like to have the amount of car sold for the previous day in a fourth column. For example, let's say I have sold 4 cars on Monday, 5 cars on Tuesday, 3 cars on Wednesday.
On the Tuesday line, I'd like to have '4' written, as it is the amount of cars sold on Monday.
I'm not sure if I make sense, let me know. Thank you for your help!
You just have to join your table on itself
SELECT A.DOTW, A.AOCS, A.PDOTW, B.AOCS
FROM
MY_TABLE A
LEFT JOIN
MY_TABLE B
ON
A.PDOTW=B.DOTW
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 5 years ago.
Improve this question
I have a mysql table that contains, among others, the columns personName, board (a bool that states if person is part of board or not) and board_date (a date column that contains the date that the person was elected to the board, if she was).
In my club, the people are elected for 5 year terms. I need to create a query that will return the people whose term will expire in the next 6 months. But I have no clue on how to do that math with those dates.
Can someone please give me a hand? I inherited this system from a previous administrator, and the client wants this. I'm not good with SQL
you can use date_add adding 6 months to now()
select *
from my_table
where date_add(board_date, INTERVAL 5 YEAR)
between now() and DATE_ADD(now(), INTERVAL 6 MONTH)