how can I count all row and count group by on one tables

Touchy Vivace

i write a SQL Code like this

    SELECT count(tn.[ProductName])  as ProductCount,tn.[CategoryID],tp.estbProducerID,tp.NewProducer
from [tpdcn] tp,[tpdtn] tn
left join [tpdcn]
on tn.parentid = tpdcn.libDocumentID
where tp.libdocumentID = @id
group by tn.[CategoryID],tp.estbProducerID

it's show

   Product Count    CategoryID     estbProducerID
        2               1            810600017   
        9               2            810600017  
        2               3            810600017  
        2               4            810600017  
        1               5            810600017

but I need more one field to show like this

 Product Count  CategoryID     estbProducerID     Product Count All   
        2               1            810600017                16
        9               2            810600017  
        2               3            810600017  
        2               4            810600017  
        1               5            810600017

What should I do to make it in one table

Mikael Eriksson

You can use OVER Clause (Transact-SQL).

count(*) over() as [Product Count All]

It will count the rows using the specified partition. Without a partition clause it count all rows.

select count(T.[ProductName]) as ProductCount,
       T.CategoryID,
       T.estbProducerID,
       T.NewProducer,
       T.[Product Count All]
from (
     select tn.[ProductName],
            tn.[CategoryID],
            tp.estbProducerID,
            tp.NewProducer,
            count(*) over() as [Product Count All]
     from [tpdcn] tp,[tpdtn] tn
       left join [tpdcn]
         on tn.parentid = tpdcn.libDocumentID
     where tp.libdocumentID = @id
     ) as T
group by T.[CategoryID],
         T.estbProducerID

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how can I count all row and count group by on one tables

From Dev

How can I count multiple foreign keys and group them in a row?

From Dev

MySQL - count and group by - display all results in one row

From Dev

MySQL - count and group by - display all results in one row

From Dev

how can I count mysql data with group by

From Dev

How I can count with GROUP BY and condition in MySQL

From Dev

How can i get gridview row count

From Dev

How can I count all cells in a row based on the value in a column in MS Excel 2010?

From Dev

How do I select a row with max count doing a group by

From Dev

How can I use cypher query to return the count of all the elements in one array?

From Dev

MySql. How can i get count from 2 tables

From Dev

COUNT of different tables in GROUP

From Dev

Count group by with three tables

From Dev

Group by count multiple tables

From Dev

Count group by with three tables

From Java

TSQL: Group by one column, count all rows and keep value on second column based on row_number

From Dev

SQL - COUNT() rows for two tables that are GROUP BY one column in one table

From Dev

How can I aggregate collection and group by field count

From Dev

How can I count a specific value in group_by in pandas?

From Dev

How can i process the ArrayList with count, and group by function

From Dev

How can I Count, group and show age from my database

From Dev

How can I optimize a query which depends on both COUNT and GROUP BY?

From Dev

How I can group by and count in PostgreSQL to prevent empty cells in result

From Dev

how can I estimate row count in mysql search query?

From Dev

How can I alternate the column count per row?

From Dev

using postgresql, how can I join tables , select all from left table and sum and count from right table?

From Dev

count all values and group by with count

From Dev

how to count row group in select mysql?

From Dev

Count and group row in MySql

Related Related

  1. 1

    how can I count all row and count group by on one tables

  2. 2

    How can I count multiple foreign keys and group them in a row?

  3. 3

    MySQL - count and group by - display all results in one row

  4. 4

    MySQL - count and group by - display all results in one row

  5. 5

    how can I count mysql data with group by

  6. 6

    How I can count with GROUP BY and condition in MySQL

  7. 7

    How can i get gridview row count

  8. 8

    How can I count all cells in a row based on the value in a column in MS Excel 2010?

  9. 9

    How do I select a row with max count doing a group by

  10. 10

    How can I use cypher query to return the count of all the elements in one array?

  11. 11

    MySql. How can i get count from 2 tables

  12. 12

    COUNT of different tables in GROUP

  13. 13

    Count group by with three tables

  14. 14

    Group by count multiple tables

  15. 15

    Count group by with three tables

  16. 16

    TSQL: Group by one column, count all rows and keep value on second column based on row_number

  17. 17

    SQL - COUNT() rows for two tables that are GROUP BY one column in one table

  18. 18

    How can I aggregate collection and group by field count

  19. 19

    How can I count a specific value in group_by in pandas?

  20. 20

    How can i process the ArrayList with count, and group by function

  21. 21

    How can I Count, group and show age from my database

  22. 22

    How can I optimize a query which depends on both COUNT and GROUP BY?

  23. 23

    How I can group by and count in PostgreSQL to prevent empty cells in result

  24. 24

    how can I estimate row count in mysql search query?

  25. 25

    How can I alternate the column count per row?

  26. 26

    using postgresql, how can I join tables , select all from left table and sum and count from right table?

  27. 27

    count all values and group by with count

  28. 28

    how to count row group in select mysql?

  29. 29

    Count and group row in MySql

HotTag

Archive