with temp_00 as ( select generate_series ('2016-08-02':: date , '2016-11-01':: date , '1 days':: interval ):: date as current_date ) select b. current_date , count ( distinct user_id) as dau from ga_sess a cross join temp_00 b where visit_stime >= (b. current_date - interval '1 days') and visit_stime < b. current_date group by b. current_date 위 SQL문에서 where visit_stime >= (b. current_date - interval '1 days') and visit_stime < b. current_date 이 부분이 이해가 가지 않습니다. current_date가 2016-08-02일 경우 visit_stime이 2016-08-02보다는 작아야 하고, 2016-08-01보다는 크거나 같다는 말인데.. 그럼 즉, 2016-08-01 00:00:00 ~2016-08-01 23:59:59 라는 건데요.. 그럼 이게 2016-08-01의 DAU가 아닌가요?.. select 절에서는 current_date로 group by를 해서 추출된 데이터는 2016-08-02의 DAU로 추출이 되더라구요.. 실제 csv파일로 받아서 보아도, 2016-08-01의 dau가 1569로 확인이 되는거 같기두 하구요.. with temp_00 as ( select generate_series ('2016-08-01':: date , '2016-11-01':: date , '1 days':: interval ):: date as current_date ) select b. current_date , count ( distinct user_id) as dau from ga_sess a cross join temp_00 b where visit_stime >= b. current_date and visit_stime < (b. current_date + interval '1 days') group by b. current_date with temp_00 as ( select generate_series ('2016-08-01':: date , '2016-11-01':: date , '1 days':: interval ):: date as current_date ) select b. current_date , count ( distinct user_id) as wau from ga_sess a cross join temp_00 b where visit_stime >= (b. current_date - interval '6 days') and visit_stime < (b. current_date + interval '1 days') group by b. current_date ; with temp_00 as ( select generate_series ('2016-08-01':: date , '2016-11-01':: date , '1 days':: interval ):: date as current_date ) select b. current_date , count ( distinct user_id) as mau from ga_sess a cross join temp_00 b where visit_stime >= (b. current_date - interval '29 days') and visit_stime < (b. current_date + interval '1 days') group by b. current_date ; 이렇게 구하는게 맞는거 아닌지 문의드립니다 !
강의 : 패턴으로 익히는 파이썬과 MySQL - 데이터 삭제와 총정리 가장 마지막에 언급하신 연습 문제 를 하고 있는데, 자꾸 에러가 뜹니다 코드--------------------------------------------- import pymysql db = pymysql.connect(host=' localhost ', port=3306, user='root', passwd='Qpspelrxm34*', db='ecommerce', charset='utf8') cursor = db.cursor() SQL = """ CREATE TABLE corw3 ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(50) NOT NULL, model_num VARCHAR(15) NOT NULL, model_type VARCHAR(30) NOT NULL, PRIMARY KEY(id) ); INSERT INTO corw2 (name, model_num, model_type) VALUES('i7', '7700', 'Kaby Lake'); INSERT INTO corw2 (name, model_num, model_type) VALUES('i7', '7500', 'Kaby Lake'); INSERT INTO corw2 (name, model_num, model_type) VALUES('i7', '7700K', 'Kaby Lake'); INSERT INTO corw2 (name, model_num, model_type) VALUES('i7', 'G4600', 'Kaby Lake'); INSERT INTO corw2 (name, model_num, model_type) VALUES('i7', '7600', 'Kaby Lake'); """ cursor.execute(SQL) result = cursor.fetchall() for record in result: --- print(record) db.commit() db.close() 에러 메세지------------------------- ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO corw2 (name, model_num, model_type) VALUES('i7', '7700', 'Kaby Lake'' at line 9") 에러에서는 INSERT INTO 부분이 이상하다고 하는 것 같은데, mysql에서는 해당 공식으로 테이블을 바꿔서 입력해도 그 테이블에 데이터가 잘 저장이 되어서요 코드에 혹시 문제가 있는건지 여쭤보고 싶습니다 아니라면 데이터베이스나 다른 테이블에 문제가 있는 건지 제가 더 고민해보도록 하겠습니다.. ㅜㅜㅎㅎ 저같은 코린이도 어떻게든 해볼 수 있게 친절하고 이해가 쏙쏙 되게 가르쳐주셔서 감사합니다!!
안녕하세요. 지금 5~6강 정도를 진행중인 수강생입니다. 평소 웹 개발을 하고 있지만 stored procedure 에 대해 생소한 부분이 많아 질문 드리려 합니다. 1. stored procedure 를 설계/적용 하는 것은 항상 하는 일은 아닌것 같습니다. 언제 하면 좋을까요? 혹은 언제 쓰면 안되는 걸까요? 가령, 현재 저는 jpa 를 이용한 개발을 하고 있는데, stored procedure 는 적용이 되지 않은 db 에서 작업을 하고 있습니다. 반대로, stored procedure 를 써서 약간의 성능 향상을 누리거나 정해진 방법 이외의 방법으로 쿼리를 못날리게 하고 싶을땐 stored procedure 를 만들어두고 사용을 권장하는 방법도 있다고 들었습니다. 아직 제가 stored procedure 의 사용처에 대해 확신이 들지 않는데, 이런 부분에 대해 알려주시면 감사하겠습니다. 2. 대댓글 설계에 참고할 만한 사항이 있을까요 ? 이것은 강의와 직접 관련한 내용은 아니지만 조언을 구하고 싶습니다. 간단하게 페이지에 대한 칼럼을 추가하고 순환 참조를 허락한 테이블을 만들면 되지만 "순환 참조를 이용한 테이블은 나쁠 것이다" 라는 편견(?)도 있어서요. 참고할만한 자료나 교수님 생각을 알려주시면 감사하겠습니다. 새해복 많이 받으세요 .
- 본 강의 영상 학습 관련 문의에 대해 답변을 드립니다. (어떤 챕터 몇분 몇초를 꼭 기재부탁드립니다) - 이외의 문의등은 평생강의이므로 양해를 부탁드립니다 - 현업과 병행하는 관계로 주말/휴가 제외 최대한 3일내로 답변을 드리려 노력하고 있습니다 - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요. 섹션 3 SQL로 데이터 삭제하고, 다양한 SQL 활용하기 강의 내용 중 10분 54초에서 제품의 가격(lowest_price)들을 UPDATE 함수 이용해서 추가하셨는데, 혹시 INSERT 를 사용해서 추가는 불가한 건가요?? INSERT INTO mytable (lowest_price) VALUES (28170); 했는데 안 되네요 ㅎㅎㅎ INSERT는 VALUES에 모든 column의 값이 다 들어가 있어야만 추가할 수 있는 함수인 건지 궁금합니다
안녕하세요, 도움을 받고자 글 올립니다. 97년 이후 nw데이터의 '국가/ 기준월 / 대표제품명 / 구매고객수 / 동시구매 고객 수 / 구매 횟수 / 동시구매 횟수 / 동시구매율' 을 구해보았는데 결과가 나오긴 하는데 맞는지 알 수가 없어서 코드리뷰 부탁드립니다. 더불어 더 좋은 코드가 있을지 여쭙습니다. 새해 복 많이 받으세요 with uu as ( select customer_id, product_id, order_id, product_name, order_date, ship_address from ( select c.product_id, c.product_name, a.amount, b.order_date, b.ship_address , b.customer_id, b.order_id from order_items a join orders b on a.order_id = b.order_id join products c on a.product_id = c.product_id where extract ( year from b.order_date) >= 1997) tt ) , xx as ( select ww.customer_id, ww.product_id as prd_01, vv.product_id as prd_02, ww.order_date, ww.ship_address from uu ww join uu vv on ww.customer_id = vv.customer_id) , temp_01 as ( select customer_id, prd_01, prd_02, extract ( year from order_date) as year_ord, extract ( month from order_date) as month_ord, ship_address as country from xx where prd_01 != prd_02 group by 1,2,3,4,5,6 order by 1,2,3,4,5,6)---------------구매자 id, 대표제품 id, 동시구매제품 id, 년, 월, 국가 , temp_03 as ( select prd_01, prd_02, count (*) as cnt_prd_prd from temp_01 group by 1,2 order by 1, 3 desc ) -----------------대표제품 id, 동시구매제품 id, 동시구매 횟수 , temp_04 as ( select distinct product_id, count (customer_id) as cnt_prd from order_items oi join orders o on oi.order_id = o.order_id group by 1 order by 1)-------------------- 대표제품 id, 구매고객수 , temp_05 as ( select prd_01, prd_02, count (customer_id) as cnt_prd_customer from temp_01 group by 1,2 order by 1,3)-------- 동시구매 고객 수 , temp_06 as ( select customer_id, count (order_id) as cnt_customer from orders group by 1)------ 구매횟수 , temp_07 as ( select distinct t5.prd_01, t5.prd_02, cnt_prd_customer as 동시구매고객수, sum (cnt_customer) as 구매횟수, cnt_prd_prd as 동시구매횟수 , cnt_prd_prd/ sum (cnt_customer) as 동시구매율 from temp_01 t1 join temp_05 t5 on t5.prd_01 = t1.prd_01 and t5.prd_02 = t1.prd_02 join temp_06 t6 on t1.customer_id = t6.customer_id join temp_03 t3 on t1.prd_01 = t3.prd_01 and t1.prd_02 = t3.prd_02 group by 1,2,3,5 order by 1,5 desc ) ---/ 동시구매 고객 수 / 구매 횟수 / 동시구매 횟수 / 동시구매율 , temp_08 as ( select distinct country, year_ord , month_ord , prd_01, cnt_prd as 구매고객수 from temp_01 t1 join temp_04 t4 on t1.prd_01 = t4.product_id order by 1,2,3,4)---국가/ 기준월 / 대표제품명 / 구매고객수 select distinct t8.*, prd_02, 동시구매고객수, 구매횟수, 동시구매횟수, 동시구매율 from temp_08 t8 join temp_07 t7 on t8.prd_01 = t7.prd_01 ;