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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help in a query

Author  Topic 

1sabine8
Posting Yak Master

130 Posts

Posted - 2007-10-29 : 07:58:46
hi, i wrote this query: SELECT new_restaurantname,(COUNT(new_serviceType)*100/COUNT(new_commentcardid)) as Percentage,new_dateofvisit,new_serviceType
FROM dbo.FilteredNew_CommentCard
GROUP BY new_restaurantname,new_dateofvisit,new_serviceType

It returns the percentage grouped by retaurantname,dateofvisit and servicetype. But what i need exactly is to return the percentage grouped by restaurantname only and i need to return the dateofvisit and servicetype but not grouping by them. But it's obliging me to group by them when parsing. Is there a way not to group by them and to return them?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-29 : 08:06:18
Is new_restaurantname a primary key column?

Select t2.new_restaurantname, t2.new_dateofvisit, t2.new_serviceType, t1.Percentage
From
(
SELECT new_restaurantname,(COUNT(new_serviceType)*100/COUNT(new_commentcardid)) as Percentage
FROM dbo.FilteredNew_CommentCard
GROUP BY new_restaurantname
) t1 Join dbo.FilteredNew_CommentCard t2
on t1.new_restaurantname = t2.new_restaurantname


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

1sabine8
Posting Yak Master

130 Posts

Posted - 2007-10-29 : 09:40:39
No new_restaurantname is not a primary key column.
It's a field in the table FilteredNewCommentCard. Any ideas?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-10-29 : 09:49:06
post your table DDL, sample data and required result


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -