Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 7th, 2006, 12:20 PM
comTxMen comTxMen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 1 comTxMen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 15 sec
Reputation Power: 0
Group value by ranges

hey guys,

Please help me out with the isue below:

I have a table with teh following fields

---------------------------
CID : OBJID : OBJPER:
---------------------------
1 1 50
1 2 70
1 3 40
1 4 90
1 5 50
1 6 55
1 7 30
1 8 49
-----------------------------------------------

another table Reports
-----------------------------------------------
CID: OBJPER<50 : OBJPER btw50-70 : OBJPER>70 :
-----------------------------------------------
1 3 4 1
------------------------------------------------

The first table contains data about a course and , each topic in it and the percetage

of students who answered them correctly

table 2 is a report table which contains the percentages separated into 3 categories.

can someone help me with sql query to do so ?


Thank you.

Menon

Reply With Quote
  #2  
Old March 9th, 2006, 05:15 AM
manoher manoher is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 2 manoher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 23 sec
Reputation Power: 0
U can use pivot method to do it as follows


select CID,[1] as "OBJPER<50",[2] as "OBJPER btw50-70",[3] as "OBJPER>70" from (

select cid,1 as "range",count(*) as "count" from stu_tab where objper<50 group by cid
union all
select cid,2,count(*) from stu_tab where objper between 50 and 70 group by cid
union all
select cid,3,count(*) from stu_tab where objper>70 group by cid
)as p pivot(sum(count) for range in ([1],[2],[3])) as pvt order by cid

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Group value by ranges


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT