Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
phoenix22
Starting Member
20 Posts |
Posted - 2006-01-19 : 17:29:35
|
| Does anyone have any suggestions as to how I can easily calculate percentages in one compact query? (eg. Overtime hours divided by regular hours where the hour type is indicated by a flag)Thanks in advance |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2006-01-19 : 18:05:51
|
| SELECT SUM(Overtime) / SUM(Regular) * 100.0 as Percent, Fullname FROM MyTable GROUP BY Fullname |
 |
|
|
phoenix22
Starting Member
20 Posts |
Posted - 2006-01-19 : 22:39:15
|
| Thanks for your reply. The problem is that the table doesn't have a separate column for hours and overtime hours. The table structure is as follows:Hours Type34 Overtime22 Reg10 Sick11 Reg2 OvertimeIs there a way to calculate the percentage of reg hours over OT hours just by using one query? Thanks |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-01-19 : 22:50:36
|
Something like this ? If not, post your table structure (not partial)select [percent] = (select sum(hours) from MyTable where type = 'Overtime') * 100.0 / (select sum(hours) from MyTable where type = 'Reg') -----------------'KH' |
 |
|
|
|
|
|