Click here to Skip to main content
15,895,827 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my table is like this: supplier table(Snumber, sname, status, birthday, city)

I am trying to answer this question:

How many suppliers have distinct their first letter of their name (not repeated) and how many supplier cities have distinct the last letter of their cities for all the suppliers who were born after 1970?


I need to look at the first letter of every sname of the table and figure out if it is repeated in that name or not... i need to output how many names had a first letter that was not repeated in that same name.


EX: sname = gordon the first letter is a g but the g isnt repeated in the name so gordon would be counted.

EX: City london n is the last letter but the n happens 2 times in london so london would not be counted.

for the cities the same but the last letter instead... i used NOT LIKE but it still doesn't seem to work

What I have tried:

SELECT(SELECT COUNT(*)
	   FROM supplier 
	   WHERE SUBSTRING(supplier.sname,1,1) NOT LIKE
       CONCAT('%',SUBSTRING(supplier.sname,1,1))) AS supplier_Count,

       (SELECT COUNT(*)
       	FROM supplier
        WHERE SUBSTRING(supplier.city,LENGTH(supplier.city) - 1,1) NOT LIKE
        CONCAT('\'',SUBSTRING(supplier.city,LENGTH(supplier.city) - 1,1),'%\'')) AS City_Count;
Posted
Updated 4-Dec-17 21:40pm
v5
Comments
RDBurmon 5-Dec-17 1:40am    
Can you give us some examples?
Santosh kumar Pithani 5-Dec-17 2:00am    
Improve your question with expected output or example.

1 solution

SELECT
      (SELECT COUNT(1) FROM supplier  WHERE supplier.sname  NOT LIKE
       '%'+left(supplier.sname,1)+'%'+left(supplier.sname,1)+'%')   AS supplier_Count,
 
      (SELECT COUNT(1)  FROM supplier  WHERE supplier.city NOT LIKE
       '%'+right(supplier.city,1)+'%'+right(supplier.city,1)+'%')   AS City_Count;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900