0

I have a requirement where I have different IDs but I want to show the count of total no of rows in the table in every row.

Example: I have total 5 rows in my table

ID | Date | Name 1 1 Jul A 2 1 Jul B 3 1 Jul C 4 1 Jul D 5 1 Jul E 

I want to show the count of all rows in every row after the name column, something like this

ID | Date | Name | Count 1 1 Jul A 5 2 1 Jul B 5 3 1 Jul C 5 4 1 Jul D 5 5 1 Jul E 5 

I have tried doing it with Count(*) but it requires a group by clause which is not outputting the desired result.

Any help would be highly appreciated.

1
  • 3
    Hint : count(*) over () ( eg. use an analytical function ) Commented Jul 2, 2024 at 17:05

1 Answer 1

0

as suggested in comment try this

select id, date_1, name , count(*) over () as cnt FROM ( select 1 as id , to_date('07/01/2024','mm/dd/yyyy') as date_1, 'A' as name from dual UNION ALL select 2 as id , to_date('07/01/2024','mm/dd/yyyy') as date_1, 'b' as name from dual UNION ALL select 3 as id , to_date('07/01/2024','mm/dd/yyyy') as date_1, 'c' as name from dual UNION ALL select 4 as id , to_date('07/01/2024','mm/dd/yyyy') as date_1, 'd' as name from dual UNION ALL select 5 as id , to_date('07/01/2024','mm/dd/yyyy') as date_1, 'e' as name from dual ); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.