Add something like this:
select id, name, address, phonenumber,
count(*) over (partition by name) as [count of name]
from PERSON . . .
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I would like to count number of times same name appears in below select statement. Can someone please advise.
Select id,name,address,phonenumber
from PERSON P
join JOB J on j.id = p.id
join PAYROLL PY on py.id = p.id
where
amt >100, p.active = 1, py.salary >100
Add something like this:
select id, name, address, phonenumber,
count(*) over (partition by name) as [count of name]
from PERSON . . .
> I would like to count number of times same name appears in below select statement. Can someone please advise.<<
Why did you fail to post DDL? Now we have to guess about keys, datatypes, constraints, and we have to correct your improper syntax. I find it amazing that you had this generic magic universal Kabbalah “_id” that changes from identifying personnel in one table to identifying jobs in another and we have no idea where things like salary are kept. I see you have only one job, because if you had more than one, the table name would have been a plural or collective noun. In a valid relational model there can never be a table named “persons”; We Need to know what role these persons play in the data model. This is as silly as having table named “Things” – too generic to ever be useful.
In short, what you posted is garbage. And not even valid garbage. Why don’t you start over and post the DDL as per instructions at the front of every SQL forum for the past 30 years?
Here is a start:
SELECT P.emp_id, P.emp_name, ???. address, ??.phone_nbr
FROM Personnel AS P, Jobs AS J, Payroll AS PY.,
WHERE PY.emp_id = P.emp_id
AND PY.salaryPY._amt > 100.00
AND P.emp_id = J.emp_id;