Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Count function

Author  Topic 

KJN94
Starting Member

2 Posts

Posted - 2015-01-08 : 05:31:34

How can I count the rows when I make new table. Here is my code:

SELECT EMPLOYEE_ID, LAST_NAME, SALARY, JOB_ID, COMMISSION_PCT, DEPARTMENT_ID, COUNT(TO_CHAR(HIRE_DATE, 'DAY')) AS NUM_EMPLOYEES
FROM EMPLOYEES
WHERE TO_CHAR(HIRE_DATE, 'Day') = 'Monday'
GROUP BY EMPLOYEE_ID, LAST_NAME, SALARY, JOB_ID, COMMISSION_PCT, DEPARTMENT_ID;

Here is the table: https://www.dropbox.com/s/03m2o6fzn1j8f8t/efewfewfewfew.PNG?dl=0
I have 10 rows, so I would like under NUM_EMPLOYEES to be displayed 10 on each row.

Please help!

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2015-01-08 : 07:27:59
Use OVER() clause..

SELECT EMPLOYEE_ID, LAST_NAME, SALARY, JOB_ID, COMMISSION_PCT, DEPARTMENT_ID, COUNT(TO_CHAR(HIRE_DATE, 'DAY')) OVER() AS NUM_EMPLOYEES
FROM EMPLOYEES
WHERE TO_CHAR(HIRE_DATE, 'Day') = 'Monday'
GROUP BY EMPLOYEE_ID, LAST_NAME, SALARY, JOB_ID, COMMISSION_PCT, DEPARTMENT_ID;

--
Chandu
Go to Top of Page
   

- Advertisement -