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 |
Jabez
Starting Member
19 Posts |
Posted - 2007-07-02 : 03:18:52
|
Hi Folks,I am stuck in forming a query.My age wise employee count sample data (department wise) is as shown below.Sample Data-----------Department [>55] [50-55] [<50] [<40] [<30]---------- ----- ------- ----- ----- -----Marketing 0 1 5 10 20Op's Support 0 3 6 5 25 Op's Tech 0 0 0 3 10 Product Tech 0 0 2 4 12Product Support 0 0 1 3 7I would require the data (sum of employee count age wise) to be categorized at a boarder level. Each category comprising of one or more departments.Operations [Op's Support + Op's Tech], Product [Product Tech + Product Support], Others [Marketing] The expected result would be.Category [>55] [50-55] [<50] [<40] [<30] [Total]--------- ----- ------- ----- ----- ----- -------Operations 0 3 6 8 35 52Product 0 0 3 7 19 29Others 0 1 5 10 20 36 Thanking you in anticipation.Jabez. |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-02 : 03:33:22
|
Do you have a table that relate Department to Category ? KH[spoiler]Time is always against us[/spoiler] |
|
|
Jabez
Starting Member
19 Posts |
Posted - 2007-07-02 : 03:47:57
|
quote: Originally posted by khtan Do you have a table that relate Department to Category ? KH[spoiler]Time is always against us[/spoiler]I don't have .. but I would want to achieve without having a relation...
|
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-02 : 03:53:12
|
use a case statement to do that and group by itselect Category = case when Department in ('Product Tech', 'Product Support') then 'Product' when Department in . . . end KH[spoiler]Time is always against us[/spoiler] |
|
|
Jabez
Starting Member
19 Posts |
Posted - 2007-07-06 : 00:56:12
|
Thanks KH. I was able to solve through your suggestions. |
|
|
|
|
|