sql - query for selecting count(*) and columns -


i have query fetches rows table , number of rows query gonna return:

select tab.*,         (select count(*)            mytable mtb           mtb.name = 'xyz'                 , mtb.type = 'tp')    mytable tab   tab.name = 'xyz'         , tab.type = 'tp' 

now if see want number of rows main query returns other columns. need use query subquery in large query. want know if there better way write query. mean repeating query count separately. can please provide more optimized form

you should use analytic function count():

select tab.*, count(*) on () totalcnt mytable tab tab.name = 'xyz' , tab.type = 'tp' 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -