전체 글(129)
-
짝수와 홀수
굉장히 간단한 문제이지만 자바를 한 지 좀 오래된 것 같아서 기초문제들부터 차근차근 풀어보려 한다 1. if문으로 해결 1 2 3 4 5 6 7 8 9 10 11 12 class Solution { public String solution(int num) { String answer; if(num%2 ==0){ answer = "Even"; } else{ answer = "Odd"; } return answer; } } Colored by Color Scripter cs 2. 삼항연산자로 해결 1 2 3 4 5 6 7 8 class Solution { public String solution(int num) { String answer = num % 2 ==0 ? "Even" : "Odd"; return..
2023.01.17 -
년, 월, 성별 별 상품 구매 회원 수 구하기
가장 정답이 이해 안 가는 문제 문제 결과 화면 결과 화면과 같이 나타나기 위해서는 날짜 부분의 달에서 0이 없어야 한다고 생각했다 01월이 아니라 1월로 뜨도록 그래서 정규식으로 0을 없앴는데 계속해서 오답이 나왔다 1 2 3 4 5 6 7 8 9 10 11 12 SELECT to_char(a.sales_date, 'yyyy') year, decode( substr(to_char(a.sales_date, 'mm'),1,1), '0', regexp_substr(to_char(a.sales_date, 'mm'), '[^0]' ,1,1) ) month, gender, count(distinct a.user_id) users FROM ONLINE_SALE A, USER_INFO B WHERE A.USER_ID..
2023.01.17 -
자동차 대여 기록에서 장기/단기 대여 구분하기
1 2 3 4 5 6 7 8 SELECT HISTORY_ID, CAR_ID, to_char(start_date, 'yyyy-mm-dd') START_DATE, to_char(end_date,'yyyy-mm-dd') END_DATE, case when (end_date - start_date)+1 >= 30 then '장기 대여' else '단기 대여' end as RENT_TYPE from car_rental_company_rental_history where to_char(start_date, 'yyyy-mm') = '2022-09' order by history_id desc; Colored by Color Scripter cs 계속 틀렸었던 이유가 (end_date - start_date)+1에서 ..
2023.01.17