|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm using MSSQL 2000. I'm trying to return a rounded integer value
for the average of the row count of a column. Example data: Value Rowcount 1 4 2 5 3 5 4 5 In the Oracle DB environment I would use: select CEIL(avg(count(x))) from TESTTABLE groupby x The result would be "5" (or "4.75" if I removed the CEIL function). MSSQL doesn't like this SQL and I get an error: Server: Msg 130, Level 15, State 1, Line 1 Cannot perform an aggregate function on an expression containing an aggregate or a subquery. I rooted around for quite a while in SQL help docs and All I could come up with was the COMPUTE clause. Is this wrong? Plus, it rounds down. Try the SQL: CREATE TABLE #t(x INT) INSERT INTO #t VALUES (1) INSERT INTO #t VALUES (1) INSERT INTO #t VALUES (1) INSERT INTO #t VALUES (1) INSERT INTO #t VALUES (2) INSERT INTO #t VALUES (2) INSERT INTO #t VALUES (2) INSERT INTO #t VALUES (2) INSERT INTO #t VALUES (2) INSERT INTO #t VALUES (3) INSERT INTO #t VALUES (3) INSERT INTO #t VALUES (3) INSERT INTO #t VALUES (3) INSERT INTO #t VALUES (3) INSERT INTO #t VALUES (4) INSERT INTO #t VALUES (4) INSERT INTO #t VALUES (4) INSERT INTO #t VALUES (4) INSERT INTO #t VALUES (4) SELECT * FROM #t SELECT count(x) FROM #t GROUP BY x COMPUTE AVG (count(x)) The result is "4". I need the next greatest integer (round up). Try as I might with nested CAST statements, I still couldn't get it to work. Somebody out there has this SQL. All helping posts would be GREATLY appreciated. Thanks in advance. Kindly, Loren |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > Help me compute average of a rowcount |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|