Jump to content
Henry Olive

FB-3,09 Count(*)

Recommended Posts

I wish everyone a healthy day.

SELECT COUNT(*), DOCNO, DOCTYPE

Returns

1...ABC10....XXX

1...ABC11....YYY

I want to get TOTAL record count of the query result that is the result like below (Total 2 records returns)

2...ABC10....XXX

2...ABC11....YYY

 

How can i get total record count of a query result ?

Thank You

Share this post


Link to post

First what a strange query, a count without Grouping clause !

 

Try this (before fb 3, solution). Really disliking this "subselect" !  

SELECT (SELECT COUNT(1) FROM ATABLE) AS TOT,DOCNO,DOCTYPE FROM ATABLE

 

 

Or use a window (analytical)  function  (here SUM(1) OVER () is the window function)


(Wow now FB3+ have analytical functions 😲)

SELECT SUM(1) OVER () FULLCOUNT, DOCNO,DOCTYPE from ATABLE

 

Edited by Serge_G
  • Like 1

Share this post


Link to post

Forgot this one, better  IMHO,  for Firebird<3 using a CTE and JOIN

WITH c as (Select count(1) nb from appose) 
select c.nb,t.* from c full join appose t on 1=1

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×