I have a matrix with rows grouped by Dept (Department). I am trying to get the actual hours / required hours percentage in a column for each row group, but I can only get the total %, not the % by group. Ex:
I should get this:
Total Employee Req Hrs Rep Hrs % Billable hrs % NonBill Hrs % Time Off %
Dept A Total 672 680 101 575 85 140 21 8 1
Emp1 168 170 101 150 89 50 29 0 0
Emp2 168 165 98 120 71 20 12 8 4
Emp3 168 175 104 155 92 20 12 0 0
Emp4 168 170 101 150 89 50 29 0 0
Dept B Total 420 428 102 365 87 80 19 4 .1
Emp5 168 170 101 150 89 50 29 0 0
Emp6 84 84 98 60 71 10 12 4 4
Emp7 168 175 104 155 92 20 12 0 0
G Total 1092 1108 101 940 86 190 17 12 1
But I get this:
Total Employee Req Hrs Rep Hrs % Billable hrs % NonBill Hrs % Time Off %
Dept A Total 1684 1675 101 1250 86 225 17 12 1
Emp1 168 170 101 150 89 50 29 0 0
Emp2 168 165 98 120 71 20 12 8 4
Emp3 168 175 104 155 92 20 12 0 0
Emp4 168 170 101 150 89 50 29 0 0
Dept B Total 1092 1108 101 1250 86 225 17 12 1
Emp5 168 170 101 150 89 50 29 0 0
Emp6 84 84 98 60 71 10 12 4 4
Emp7 168 175 104 155 92 20 12 0 0
G Total 1092 1108 101 940 86 190 17 12 1
The totals are correct but the % is wrong.
I have several Datasets because the report only runs the department you are in, except for the VPs who can see all departments.
I Insert the percentage columns into the matrix and have tried several expressions with no results including:
=Fields!ActHrs.Value/Fields!ReqHrs.Value
=Sum(Fields!ActHrs.Value, "Ut_Query")/Sum(Fields!ReqHrs.Value, "Ut_Query")
=Sum(Fields!ActHrs.Value, "Ut_Query","Dept")/Sum(Fields!ReqHrs.Value,
"Ut_Query","Dept")
=Sum(Fields!ActHrs.Value,"Dept", "Ut_Query")/Sum(Fields!ReqHrs.Value,
"Dept","Ut_Query")
Plus more I can't even remember.
I tried creating new groups, and even a new matrix.
There must be a simple way to get the percentage by group but I have not found an answer on any of the interned boards.
OK, I figured this out, but it doesn't make much sense. If I try:
=Textbox29/TextBox28 I get error messages about undefined variables.
If I go the the textbox properties and rename the textboxes to Act and Req and use:
=Act/Req I get the right answer.
Related
I have 1000+ customers. I require customer report.
Here debit = potato + onion + ginger. Credit is commission.Balance will be updated every time. It will be balance - debit and balance + credit alternatively.
Grocery data report is as: Data is filled through php form with mysql_fetch_array query. Here few customers are as sample. and few data fields.
id cus_id cus_name potato onion ginger debit credit balance
1 12 munna 10 25 28 63 0 37
2 16 anil 24 56 84 164 0 136
3 34 palash 17 47 51 115 0 85
4 45 dimpy 35 64 39 138 0 112
Table grocery before and after entering new data:
id cus_id cus_name potato onion ginger debit credit balance
1 12 munna 10 25 28 63 0 37
2 16 anil 24 56 84 164 0 136
3 34 palash 17 47 51 115 0 85
4 45 dimpy 35 64 39 138 0 112
5 12 munna 0 0 0 0 6 43
6 16 anil 0 0 0 0 16 152
7 34 palash 0 0 0 0 12 97
8 45 dimpy 0 0 0 0 14 126
My problem is :
I am unable to update balance column, cus_name wise and cus_id wise and insert all data into mysql database. Suggest me with mysql query.
purchase_request_master
prm_voucher_no| project_id| status_id| request_date
17 46 3 11-6-2016 0:00
18 46 3 20-6-2016 0:00
19 46 3 216-2016 0:00
purchase_request_details
prm_voucher_no| item_id| request_quantity
17 80 50
17 81 100
18 80 75
19 83 10
19 81 35
19 82 120
purchase_order_master
pom_voucher_no| prm_request_id |supplier_id
16 17 14
17 18 14
18 19 15
purchase_order_details
pom_voucher_no| approved_quantity| rate
16 50 1000
16 100 1500
17 75 150
18 10 2500
18 35 3000
18 120 1700
when I run the below query it gives 14 rows(duplicate row returning).expected out put row is 6.. Please refer below output tables..
select prm.prm_voucher_no,prm.project_id,prm.status_id,prd.requested_quantity,prd.item_id,pom.pom_voucher_no,pom.supplier_id,pod.rate,pod.approved_quantity
from purchase_request_master prm
left join purchase_request_details prd on prd.prm_voucher_no=prm.prm_voucher_no
left join purchase_order_master pom on prm.prm_voucher_no=pom.request_id
left join purchase_order_details pod on pom.pom_voucher_no=pod.pom_voucher_no
where prm.project_id=46 and ( EXTRACT(MONTH FROM prm.request_Date)=6) and (EXTRACT(YEAR FROM prm.request_Date)=2016)
group by prm.voucher_no,prm.project_id,prm.status_id,prd.requested_quantity,prd.item_id,pom.voucher_no,pom.supplier_id,pod.rate,pod.approved_quantity
order by prm.voucher_no
i tried inner join,distinct,distinct least,group by,temporary table,with clause all these method.. but no use every this gives duplicate row
How to solve this problem..
OUTPUT
prm_voucher_no| project_id| status_id|item_id|request_quantity |pom_voucher_no| supplier_id|approved_quantity | rate
17 46 3 80 50 16 14 100 1000
17 46 3 81 100 16 14 75 1500
17 46 3 80 75 16 15 10 150
17 46 3 81 10 16 14 35 10
18 46 3 81 35 17 14 120 35
19 46 3 80 120 18 15 50 120
19 46 3 81 50 18 14 100 1000
19 46 3 82 100 18 14 75 1500
19 46 3 80 75 18 15 10 150
19 46 3 81 10 18 14 35 10
19 46 3 82 35 18 14 120 35
19 46 3 80 120 18 15 35 120
19 46 3 81 35 18 14 50 1500
19 46 3 82 50 18 15 100 1700
EXPECTED OUTPUT
prm_voucher_no| project_id| status_id| item_id| request_quantity| pom_voucher_no| supplier_id|approved_quantity| rate
17 46 3 80 50 16 14 100 1000
17 46 3 81 100 16 14 75 1500
18 46 3 81 35 17 14 120 35
19 46 3 80 120 18 15 50 120
19 46 3 81 50 18 14 100 1000
19 46 3 82 100 18 14 75 1500
I think the problem is in your data model itself. Ideally, you would have a line_number field in both of your "detail" tables, and this would be used in the join:
create table purchase_request_details (
prm_voucher_no integer,
prm_voucher_line integer, // Add this
item_id integer,
request_quantity
)
create table purchase_order_details (
pom_voucher_no integer,
pom_voucher_line integer, // and this
approved_quantity integer,
rate integer
)
And then this query would give you the results you seek:
select
prm.prm_voucher_no,prm.project_id,prm.status_id,prd.request_quantity,
prd.item_id,pom.pom_voucher_no,pom.supplier_id,pod.rate,pod.approved_quantity
from
purchase_request_master prm
left join purchase_request_details prd on
prd.prm_voucher_no=prm.prm_voucher_no
left join purchase_order_master pom on
prm.prm_voucher_no=pom.prm_request_id
left join purchase_order_details pod on
pom.pom_voucher_no=pod.pom_voucher_no and
prd.prm_voucher_line = pod.pom_voucher_line // This is the key
where
prm.project_id=46 and
EXTRACT(MONTH FROM prm.request_Date) = 6 and
EXTRACT(YEAR FROM prm.request_Date) = 2016
order by prm.prm_voucher_no
If you have no ability to control the data model, then I think the best you can do is artificially add a line number. I don't recommend this at all, as you are presupposing a lot of things, most notably that the order of records in the one table automatically correlates to the order of records in the other -- and I'm betting that's far from a guarantee.
Adding a line number would be done using the row_number() analytic, and PostgreSQL has that but MySQL does not... you have both tags in your question. Which DBMS are you using?
If you can't add line numbers, can you add item_id to your purchase_order_details table? This would likely handle your issue, unless you can have the same item on multiple lines within a purchase request/order.
In the data you have above, a join on the requested quantity (prd.request_quantity = pod.approved_quantity) fixes your issue, but I am highly confident that this would burn you when you started running it against real data.
I am using SQL Server 2008 R2.
I am having a database table that contains some user data as given below :
Id UserId Sys Dia ReadingType DataId IsDeleted
1 10 98 65 last 1390556024216 0
2 10 99 69 average 1390556024216 0
3 10 102 96 last 1390562788540 0
4 10 102 96 average 1390562788540 0
5 11 130 98 last 1390631241547 0
6 11 130 98 average 1390631241547 0
7 2 285 199 first 1390770562374 0
8 2 250 180 last 1390770562374 0
9 2 267 189 average 1390770562374 0
10 1 258 180 first 1391191009457 0
11 1 258 180 last 1391191009457 0
12 1 258 180 average 1391191009457 0
13 1 285 199 additional 1391191009457 0
14 22 110 78 last 1391549208338 0
15 22 123 83 last 1391549208349 0
In this table, there are records that are having the same DataId but different ReadingType.
I want to set IsDeleted=1 for the records having ReadingType='last' and having a record with ReadingType='average' with the same DataId, Sys, Dia and UserId.
So the Desired result shoul be :
Id UserId Sys Dia Reading DataId IsDeleted
1 10 98 65 last 1390556024216 0
2 10 99 69 average 1390556024216 0
3 10 102 96 last 1390562788540 1
4 10 102 96 average 1390562788540 0
5 11 130 98 last 1390631241547 1
6 11 130 98 average 1390631241547 0
7 2 285 199 first 1390770562374 0
8 2 250 180 last 1390770562374 0
9 2 267 189 average 1390770562374 0
10 1 258 180 first 1391191009457 0
11 1 258 180 last 1391191009457 1
12 1 258 180 average 1391191009457 0
13 1 285 199 additional 1391191009457 0
14 22 110 78 last 1391549208338 0
15 22 123 83 last 1391549208349 0
Here the records with Id 3, 5 and 11 should be marked as deleted as they are having same UserId, Sys, Dia, DataId and ReadingType="last" with another record having ReadingType="average" with same other fields.
Can anyone help me how to find out such a records and update them?
Just use UPDATE with EXISTS subquery:
UPDATE T
SET IsDeleted=1
WHERE
ReadingType='last'
AND
EXISTS(SELECT * FROM T as T1
WHERE T1.ReadingType='average'
AND T1.DataId=T.DataId
AND T1.Sys=T.Sys
AND T1.Dia=T.Dia
AND T1.UserId=T.UserId
)
SQLFiddle demo
You Can solve many way but here i am using the sub-query to solve your problem
UPDATE TABLE SET IsDeleted=1
WHERE DataId=(SELECT DataId FROM TABEL WHERE Reading='last')
I just reviewed this question but what I need is something quite different.
However, I have this table:
team_players_order
(team_id,
player_id,
ordering,
captain
)
The table stores a list of teams ids along with their players ids that belong to each team (each team could get 0-15 players). What I want to get is the teams that have a common players among them.
The list of teams I want to compare could be known (I have their ids)or unknown, then I might need to search the whole table and compare all teams. .
Here's a sample data for three teams:
team_id player_id ordering captain
117 134 0 N
117 55 1 N
117 97 2 N
117 215 3 N
117 165 4 N
117 221 5 N
117 163 6 N
117 128 7 N >> common player
117 180 8 N
117 96 9 N
117 162 10 N
117 88 11 N
117 229 12 N
117 91 13 N
117 105 14 N
-----------------------------------------------
124 88 0 N
124 165 1 N
124 92 2 N
124 130 3 N
124 47 4 N
124 221 5 N
124 30 6 N
124 223 7 N
124 105 8 Y
124 6 9 N
124 96 10 N
124 120 11 N
124 198 12 N
124 128 13 N >> common player
124 202 14 N
-----------------------------------------------
125 256 0 N
125 58 1 N
125 10 2 N
125 47 3 N
125 103 4 N
125 167 5 N
125 221 6 N
125 128 7 N >> common player
125 105 8 N
125 96 9 Y
125 180 10 N
125 210 11 N
125 229 12 N
125 30 13 N
125 33 14 N
As you can see, player 128 is common player among these three teams. I need to find other common players as well.
What I have tried so far is the following query which I guess is comparing each giving team with all other teams and get any common player that exists individually of each comparison.
SELECT
t1.team_id,
t1.player_id,
t2.team_id,
t2.player_id
FROM team_players_order AS t1
INNER JOIN team_players_order AS t2
ON (t1.team_id != t2.team_id
AND t1.player_id = t2.player_id)
WHERE t1.team_id IN(117,124,125)
AND t2.team_id IN(117,124,125)
ORDER BY t1.team_id, t2.team_id
which returns:
team_id player_id team_id player_id
117 221 124 221
117 88 124 88
117 96 124 96
117 105 124 105
117 128 124 128
117 165 124 165
117 180 125 180
117 221 125 221
117 229 125 229
117 96 125 96
117 105 125 105
117 128 125 128
124 128 117 128
124 165 117 165
124 221 117 221
124 88 117 88
124 96 117 96
124 105 117 105
124 128 125 128
124 30 125 30
124 221 125 221
124 47 125 47
124 96 125 96
124 105 125 105
125 128 117 128
125 180 117 180
125 221 117 221
125 229 117 229
125 96 117 96
125 105 117 105
125 128 124 128
125 221 124 221
125 30 124 30
125 47 124 47
125 96 124 96
125 105 124 105
But what I want is:
the players that exist in all giving teams (by their ids)
the player that exist in all teams.
n.b. the list of teams could reach to 100 once it's given.
HAVING is the solution
the player that exist in all teams
select team_id, player_id, count(*) nb from team_players_order
group by player_id
having nb > 1
the players that exist in all giving teams
select team_id, player_id, count(*) nb from team_players_order
where team_id in (124, 117)
group by player_id
having nb > 1
You can use "HAVING COUNT" in order to know which player is in multiple teams.
SELECT player_id FROM team_players GROUP BY team_id HAVING COUNT(team_id) > 1
And to list teams that have a player in other teams :
SELECT team_id FROM team_players GROUP BY team_id HAVING COUNT(player_id) > 1
Hope that helps !
I have a table like this.
id day1 day2 day3
1 411 523 223
2 413 554 245
3 417 511 209
4 420 515 232
5 422 522 212
6 483 567 212
7 456 512 256
8 433 578 209
9 438 532 234
10 418 555 223
11 460 510 263
12 453 509 245
13 441 524 233
14 430 543 261
15 456 582 222
16 444 524 241
17 478 511 211
18 421 583 222
I want to select all the IDs that have duplicate values in day2.
I'm doing
select day2,count(*) from resultater group by day having count(*)>1;
Is it possible to list all the IDs within the groups?
select day2,count(*), group_concat(id)
from resultater
group by day
having count(*)>1;
should do the trick.