question

lakshmi nair avatar image
lakshmi nair asked

over() clause

You have a table named products. The table contains a column named color. you need to write a t-sql statement that calculated the percentage of products of each product color. which transact sql statement should you use? 1. select color count(\*) over(partition by color)/ count(\*)\*1.0 as percentcolor from products group by color. 2. select color count(\*) over()/(count(\*)\*1.0) as percentcolor /(count(\*)\*1.0) as percentcolor from products group by color 3. select color, (count(\*)\*1.0)/count(\*) over() as percentcolour from products group by color 4. select color,(count(\*)\*1.0)/count(\*) over(partition by color) as percentcolor from products group by color This question s very simple but am unable to figure out the answer. can anyone tell me the correct answer with explanation thanks lakshmi nair
sql-server-2008homeworkexam-question
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Why do I think we're doing homework here?
3 Likes 3 ·
This could be done even easier if you have AdventureWorks database handy. It has a table name Production.Product which has Color column. Try your queries against this table to see which one (if any) will return correct results. Please note that first 2 queries probably produce invalid SQL (missing a comma after the word reading color).
3 Likes 3 ·
@lakshmi nair : have you tried mocking up a table with these columns and trying each of the options?
0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.