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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 distinct query

Author  Topic 

mkool
Starting Member

25 Posts

Posted - 2008-02-19 : 13:59:28
select distinct code,id,pageno,price,sum(price) as total from pagetab

i m getting rows of - same pageno but different codes...

i want different pagenos but different codes sum(price)

how can i get it?

select distinct code,id,pageno,price,sum(price) as total from pagetab
where code=code and pageno<>pageno

it gives me error

talleyrand
Starting Member

35 Posts

Posted - 2008-02-19 : 17:39:55
In general, if you're experiencing an error it is highly helpful, encouraged even to post what the error is. I'll assume you are seeing a message about "Column 'pagetab.code' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."

To resolve this, you are most likely interested in
SELECT
PT.code
, PT.id
, PT.pageno
, PT.price
, sum(PT.price) AS total
FROM
pagetab PT
GROUP BY
PT.code
, PT.id
, PT.pageno
, PT.price


I'm not sure about your where clause, that should give you no results unless you have a join that you did not show.

Go to Top of Page
   

- Advertisement -