# Thread: How can I overtake categorized data for doing operations

1. ## How can I overtake categorized data for doing operations

Below table is my favorite result (please click on image to enlarge it) :

I have problem with calculation of weightPercent column :
In above table (20) is calculated as described below :
(200/(200+300)) * (100/200) * 100 = 20
So query should be something like :
Code:
```SELECT   projectID
,projectName
,orderAmount
,delivered
,((orderAmount/(?)) * (delivered/orderAmount) * 100) AS weightPercent
Group By projectName;```
I don`t know how should I interact with (?) mark in above query ? I need to calculate that summation for every project
separately .
P.S : Above query is a abridgement of one complicated query . I tested SUM(DISTINCT *) but I got many problems with it ,
so I`m looking for any other solution ;Is there any other trick for it ?

2. Originally Posted by omid020
In above table (20) is calculated as described below :
(200/(200+300)) * (100/200) * 100 = 20
what are those numbers? where do they come from?

3. I have placed one screenshot that shows the final result; those numbers are description of how (20) is obtained from first row of that table.That is just one example to show how table should work to calculate "weightPercent".

4. (200--->from orderAmount/(200+300)--->from orderAmount) * (100---->from delivered/200---->from orderAmount) * 100 = 20

5. Code:
```SELECT daTable.projectID
, daTable.projectName
, daTable.orderAmount
, daTable.delivered
, daTable.delivered * 100.0 /
subtotals.project_amount AS weightPercent
FROM ( SELECT projectName
, SUM(orderAmount) AS project_amount
FROM daTable
GROUP
BY projectName ) AS subtotals
INNER
JOIN daTable
ON daTable.projectName = subtotals.projectName```

6. Interesting solution , TNX

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•