# need help to find ratio

 0 Hi,I need a small help from the Ask SSC members. I need to find the ratio using sql and print it in the output.The scenario is i have a total of 1800 records and i have splitted the whole 1800 records into two portions. One part will have 1200 records with the company name a and the company name b will have remaining 600 records.I am able to get the output in the following format![alt text][1]i want to find the ratio of the two number 1200 and 600.Can anyone please help me in this regard? [1]: /storage/temp/241-\untitled.gif \untitled.gif (10.9 kB) more ▼ asked Jun 15 '12 at 11:55 AM in Default Karthik Venkatraman 72 ● 7 ● 9 ● 10 what does the ratio refer to? What is it the ratio of, to? Jun 15 '12 at 12:03 PM Kev Riley ♦♦ Karthik, you have edited your question (and removed the example output), but still not fully explained how you want to find the ratio. Given the data above, what result are you expecting? Jun 19 '12 at 08:53 AM Kev Riley ♦♦ Hi,i need the ratio of the two numbers 1200 and 600 in row 1 and 2. The ratio needs to be displayed in a new column after the column with heading "Count". The ratio of 1200 and 600 will be 2:1 and it needs to be displayed after the count. I have function to find the ratio of the two numbers. but since i dont want to use function i want to find the ratio using the normal mathematical calculations if possible. Jun 20 '12 at 07:57 AM Karthik Venkatraman So my answer below works for you then? Jun 20 '12 at 08:12 AM Kev Riley ♦♦ add new comment (comments are locked) 10|1200 characters needed characters left ▼ Viewable by all users

1 answer: sort voted first
 0 If 2 in the ratio is the count of how many companies there are, then it's a simple `count(*)over()` ``````select CompanyName, count(*) as Count, cast(count(*)over() as varchar) +':1' as Ratio from YourTable group by `````` CompanyName more ▼ answered Jun 15 '12 at 12:23 PM Kev Riley ♦♦ 50.8k ● 43 ● 49 ● 76 add new comment (comments are locked) 10|1200 characters needed characters left ▼ Viewable by all users
Your answer

### New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1816
x362

asked: Jun 15 '12 at 11:55 AM

Seen: 803 times

Last Updated: Jun 20 '12 at 08:12 AM