1

For displaying the total page number count I need also to retrieve total number of results at the below query. How can I do that ?

Thank you

select 
    AvgLevel, TotalCount, PokemonId, Type1, Speed, MonsterTotalStats 
from 
   (select 
       row_number() over (order by tblPokedex.PokemonId asc) rowNumber,
       AvgLevel, TotalCount, tblPokedex.PokemonId, 
       Type1, tblPokedex.Speed, MonsterTotalStats
    from 
       tblPokemonStats, tblAvailablePokemons, tblPokedex 
    left join 
       tblUsersPokemons on tblPokedex.PokemonId = tblUsersPokemons.PokemonId  
    where 
       tblPokemonStats.PokemonId = tblPokedex.PokemonId 
       and tblPokedex.Class = 'emissary' 
    group by 
       tblPokedex.PokemonId, tblPokedex.Type1, tblPokedex.Speed, 
       tblPokemonStats.AvgLevel, tblPokemonStats.TotalCount, MonsterTotalStats 
   ) result 
where 
    result.rowNumber > 0 and result.rowNumber < 101
1
  • 2
    thanks for editing @marc_s looks better now Commented Nov 30, 2012 at 12:47

2 Answers 2

2

Just add column Count(*) over():

..... 
select row_number() 
over (order by tblPokedex.PokemonId asc) rowNumber,
AvgLevel,
Count(*) over() as TotalCount,
.......

see example

select 
AvgLevel,TotalCount,PokemonId,Type1,Speed,MonsterTotalStats, TOTALRECORDCOUNT
from (
select row_number() 
over (order by tblPokedex.PokemonId asc) rowNumber,AvgLevel,TotalCount,tblPokedex.PokemonId,Type1,tblPokedex.Speed,MonsterTotalStats,
count(*) over() as TOTALRECORDCOUNT
from tblPokemonStats,tblAvailablePokemons,tblPokedex left join tblUsersPokemons on tblPokedex.PokemonId=tblUsersPokemons.PokemonId  
where tblPokemonStats.PokemonId=tblPokedex.PokemonId and tblPokedex.Class='emissary' 
group by tblPokedex.PokemonId,tblPokedex.Type1,tblPokedex.Speed,tblPokemonStats.AvgLevel,tblPokemonStats.TotalCount,MonsterTotalStats 
)  
result where result.rowNumber>0 and result.rowNumber<101
Sign up to request clarification or add additional context in comments.

6 Comments

TotalCount is a parameter that exists on another table that shows how many monsters catched by players.
Ok call it "TotalRecordCount" so total count of records will be in each record you get from this query.
oh my bad. i saw it wrong. but it displays fetched row count which is 100 while there are total 527 records. so not working as intended.
You should use it in the inner query as in my example then it outputs ALL rows count in inner query before your WHERE in the outer query.
thanks working great. but your way or this way is better ? stackoverflow.com/questions/4007803/…
|
1

You coud use :

SELECT @@ROWCOUNT

check it out here.

6 Comments

how do i add it to the query ?
it's a separate query, just use it below your query
i checked and it display the row count retrieved. so it displays 100 not the total number of possible results. Total number is 527 for example.
What are you trying to retrieve the total of?
Total available records. I am paginating between records. Like retrieve between 1-100 or 100-200. There is a total number of records which is for example for this query 527. So i also want to obtain that number in this query.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.