Display Employees Names Who Have 2L's, SQL Query
My code so far is:
select ename from emp where ename =ll%;
The question开发者_JS百科 is, display all the names of all employees who have 2Ls in their name and are in department 30 or their manager is 7782;
I tried my code but it is giving me errors, I'm practicing for my test.
You want to use the like command and sandwich your ll's w/ % wild cards:
select ename from emp where ename like '%ll%'
Do you mean "two l's like hello", or "two l's like lala"? If the second, this might work:
SELECT
ename FROM emp
WHERE
ename LIKE '%l%l%'
AND
(department = 30 AND manager = 7782)
If the first, change the LIKE
to %ll%
instead.
If department
and manager
are CHAR/VARCHAR
instead of numeric, you'll need single quotes around them as well.
Select * from emp
Where instr(ename, 'l', 2, 2)>1 and
(Department=30 or manager=7782);
Here in instr function I start search from 2nd position to make it efficient. N no. Of occurance will be 2 as his query all about the 2nd 'l'.
SELECT ename
FROM emp
WHERE (ename LIKE '%l%l%'
OR ename LIKE '%ll%')
AND (department = 30 AND manager = 7782) ;
SELECT ename FROM emp
WHERE instr(ename,'L',1,2)>1 AND department =30 AND manager = 7782
Try this:
SELECT *
FROM EMP
WHERE LENGTH(ENAME)-LENGTH(REPLACE(ENAME,'L'))>=2;
It will work.
精彩评论