Count number of times particular value is resent in select statement

Sourabh Agrawal 41 Reputation points
2021-02-04T19:58:22.487+00:00

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

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,601 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Joe Celko 16 Reputation points
    2021-02-04T20:31:51.983+00:00

    > 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;

    0 comments No comments