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
 query-help needed

Author  Topic 

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-04-26 : 02:32:54
hi
i have a table with below structure
id no.of visit no of sales no of delivery.

I want all records to be selected with the following data also
average( no.of visit),average( no of sales ), average( no of delivery) in a single query ?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-26 : 02:34:28
SELECT id,avg( [no.of visit]),avg( [no of sales] ), avg( [no of delivery])
FROM YourTable
GROUP BY id
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-04-26 : 02:39:24
hi visakh,
i want not only averages,but also all records also.
just like below...
select * from table with average of the three fields I mentioned above.All in a single query.

ok thanks..

Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-04-26 : 02:56:15
might be better to post sample data and expected results


elsasoft.org
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-04-26 : 03:00:27
hi
sample data
id novisit noenquiry nodelivery
1 20 30 10
2 40 40 10

i want

1 20 30 10
2 40 40 10
30 35 10

ok
thanks
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-04-26 : 03:06:47
select id, novisit, noenquiry, nodelivery from yourtable
union all
select null, avg(novisit), avg(noenquiry), avg(nodelivery) from yourtable


elsasoft.org
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-04-26 : 03:35:27
hi all
thanks for ur replies..
ok
Go to Top of Page
   

- Advertisement -