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.
| Author |
Topic |
|
mavershang
Posting Yak Master
111 Posts |
Posted - 2008-11-20 : 11:02:59
|
| Hey guys. I have a question about SQL query.Here is my query:SELECT AVG(COL1),AVG(COL2)FROM.....WHERE....Because this query is in a repeating cycle, so sometimes it will get multiple rows but sometimes only a single row. Then if it is a single row, the AVG() did not work and can not return any value.How to deal with that?Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-20 : 11:08:40
|
| didnt understand what you're talking. can you explain with some data sample? |
 |
|
|
mavershang
Posting Yak Master
111 Posts |
Posted - 2008-11-20 : 11:10:58
|
OK. So the point is does "AVG()" work if I only select a single row?quote: Originally posted by visakh16 didnt understand what you're talking. can you explain with some data sample?
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-20 : 11:17:18
|
quote: Originally posted by mavershang OK. So the point is does "AVG()" work if I only select a single row?quote: Originally posted by visakh16 didnt understand what you're talking. can you explain with some data sample?
nope. AVG returns of the average of the quantity specified over grouping applied (if no grouping applied then it gives average for table) |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-11-20 : 11:48:27
|
[code]DECLARE @Sample TABLE ( data MONEY )INSERT @SampleSELECT 4.5SELECT AVG(data)FROM @Sample[/code]There must be something else wrong with your code. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|