sum base on other criteria and place summed values on each rows - group-by

I have a table as follow:
Empl Dates Hour
Emp1 date1 8
Emp1 date2 5
Emp1 date3 4
Emp2 date1 1
Emp2 date2 3
Emp2 date3 5
....
How do I sum hours for employees and place the sum value on each rows of in MSAccess Query and not the SQL?
like
Empl Dates Hour Sum of Hours
Empl1 date1 8 17
Empl1 date2 5 17
Empl1 date3 4 17
Empl2 date1 1 9
Empl2 date2 3 9
Empl2 date3 5 9
and so on.

Related

Group Results By Month and Column

Is there anyway i can group the results by month and by type? With the query below i managed to group by month but the "type" is not grouping.
query:
select date_trunc('month',processingdate),type,sum(itemcount), sum(itemamount)
from test
where date_trunc('month',processingdate) >= now() - interval '1 month'
group by type,date_trunc('month',processingdate)
order by processingdate
Data in table:
date_trunc type sum sum
1/1/20 11 5 1
1/2/20 12 3 2
1/3/20 11 2 3
1/4/20 12 3 5
Expected Results:
date_trunc type sum sum
1/1/2020 11 7 4
1/1/2020 12 6 7

Convert Name of day to number -e.g- Monday to 1

I don't have timestamp table. I just need to convert using name string,
SELECT day_of_week;
Output should look like
day_of_week sum
Friday 5
Monday 1
Saturday 6
Sunday 7
Thursday 4
Tuesday 2
Wednesday 3
If it were timestamp then you can use the isodow. See doc
isodow
The day of the week as Monday(1) to Sunday(7)
SELECT day_of_week, EXTRACT(ISODOW FROM TIMESTAMP '2001-02-18 20:38:40') as sum FROM your_table;
But you don't have that column. So you can use CASE...WHEN like below-
SELECT day_of_week,
CASE WHEN day_of_week='Monday' THEN 1
WHEN day_of_week='Tuesday' THEN 2
WHEN day_of_week='Wednesday' THEN 3
WHEN day_of_week='Thursday' THEN 4
WHEN day_of_week='Friday' THEN 5
WHEN day_of_week='Saturday' THEN 6
ELSE 7
END as sum
FROM your_table;
See doc: https://www.postgresql.org/docs/8.4/functions-conditional.html

How modify and use totals in tableau

I have several measures names and 5 dates and I need to create a calculated field over the first 4 dates and use the result in news calculated fields with the 5 date
date1 date2 date3 date4 date5 AVGdate1-4
measure1
measure2
.
.
measureN

How to get last 3 Months of "Monday to Sunday" dates In Redshift?

How can I get last 3 Months of "Monday to Sunday" dates in Redshift?
S.no Start_dt End_dt week
1 18-Jul-16 24-Jul-16 Week1
2 25-Jul-16 31-Jul-16 Week2
3 1-Aug-16 7-Aug-16 Week3
4 8-Aug-16 14-Aug-16 Week4
5 15-Aug-16 21-Aug-16 Week5
6 22-Aug-16 28-Aug-16 Week6
7 29-Aug-16 4-Sep-16 Week7
8 5-Sep-16 11-Sep-16 Week8
9 12-Sep-16 18-Sep-16 Week9
10 19-Sep-16 25-Sep-16 Week10
11 26-Sep-16 2-Oct-16 Week11
12 3-Oct-16 9-Oct-16 Week12
13 10-Oct-16 16-Oct-16 Week13
I've tried this:
select
trunc(date_trunc('week',sysdate)) st_dt,
trunc(date_trunc('week', sysdate)+6) ed_dt,
'week'||row_number() over (order by null) as week
but it only returns the current week's Monday and Sunday.
You can use generate_series() to generate a range of dates:
SELECT
trunc(day) as start_date,
trunc(day + 6) as end_date
FROM
(select date_trunc('week', sysdate) + (generate_series(1, 12) * interval '1 week') as day)
ORDER BY 1 ASC
This results in:
week start week end
2016-10-24 2016-10-30
2016-10-31 2016-11-06
2016-11-07 2016-11-13
2016-11-14 2016-11-20
2016-11-21 2016-11-27
2016-11-28 2016-12-04
2016-12-05 2016-12-11
2016-12-12 2016-12-18
2016-12-19 2016-12-25
2016-12-26 2017-01-01
2017-01-02 2017-01-08
2017-01-09 2017-01-15
Please note that generate_series() in Amazon Redshift cannot be joined with existing tables. It can only be used as a "Leader-only" query.

Jasper reports table

I created a table with jasper, the table is created fine but I only want to jasper shows the table from:
Group1
id Date
1 date1
2 date2
3 date3
Group1
id Date
1 date1
2 date2
3 date3
to:
Group1 Group2
id Date id Date
1 date1 1 date1
2 date2 2 date2
3 date3 3 date3
I checked the value group's porperty "start new column" but this not work fine and the result is like the first example
Thanks