SELECT
user_id
, CONCAT(UPPER(SUBSTRING(name,1,1)),LOWER(SUBSTRING(name,2))) AS name
FROM
Users
ORDER BY
user_id
;
→ MySQL에는 문자열의 첫 글자만 대문자로 쓸 수 있는 함수가 없음 🡆 함수 중첩을 사용
오라클은 INITCAP이 있다고 함
SELECT user_id, CONCAT(UPPER(LEFT(name,1)),LOWER(RIGHT(name,LENGTH(name)-1))) AS name
FROM Users
ORDER BY user_id ASC;
SELECT
*
FROM
Patients
WHERE
conditions LIKE 'DIAB1%'
OR conditions LIKE '% DIAB1%'
;
→ 정규표현식으로도 쓸 수 있을 텐데 방법을 모르겠음
SELECT *
FROM Patients
WHERE conditions REGEXP '(^|\\s)DIAB1[0-9]*';
select * from patients
where conditions regexp "[ ]DIAB1|^DIAB1"
🡆 또 다른 방식으로도 적을 수 있나 궁금해서 더 찾아보았음
SELECT * FROM patients WHERE conditions REGEXP '\\bDIAB1'
The expression conditions REGEXP
\\bDIAB1is actually the same as conditions LIKE '% DIAB1%' OR conditions LIKE 'DIAB1%';, but it is obviously shorter.
The reason they are the same is that \b matches either a non-word character (in our case, a space) or the position before the first character in the string.
Also, you need to escape a backslash with another backslash, like so:\\b.
Otherwise, the regular expression won't evaluate.
P.S.\balso matches the position after the last character, but it doesn't matter in the context of this problem.
→ 추가: 해당 쿼리는 현재 testcase는 통과 못한다고 함

🡆 \b가 a non-word character라 space 말고 다른 특수문자도 다 통과시킴



def solution(s):
answer = []
s_dict = {}
for idx, i in enumerate(s):
if i not in s_dict:
answer.append(-1)
else:
answer.append(idx-s_dict[i])
s_dict[i] = idx
return answer
def solution(s):
answer = []
dic = dict()
for i in range(len(s)):
if s[i] not in dic:
answer.append(-1)
else:
answer.append(i - dic[s[i]])
dic[s[i]] = i
return answer
- 딕셔너리에 없는 알파벳이 나오면
- answer 리스트에 -1 추가
- dic 딕셔너리에 {알파벳:현재 인덱스} 추가
- 딕셔너리에 있는 알파벳이 나오면
- answer 리스트에 (현제 인덱스 - dic[알파벳]) 값 추가
- dic 딕셔너리 값을 현재 인덱스로 바꿔주기
def solution(s):
answer = []
for i in range(len(s)):
if s[i] in s[:i] and i>0 :
temp = list(reversed(s[:i]))
answer.append(temp.index(s[i])+1)
else :
answer.append(-1)
return answer
def solution(s):
return [s[i::-1].find(s[i],1) for i in range(len(s))]
→ 한 줄로 쓸 수 있다니 정말 멋지다!