춘봉

도와주세요!! 개발자님들!

· 2017-05-15 (월) 13:02:59 · 2995 · 6

안녕하세요. 오랜만에 접속하네요.

질문이 있을때 마다 SIR를 찾게되네요. 전문가분들이 너무 많으셔서요.

 

메인 검색

select substr(hv_datetime, 12, 2) as Times from hit_visit group by Times 

하위 검색

select count(*) as Count from hit_visit where (1) and hv_set = 'Visit' and hv_datetime like '% ".$Row[0]['Times'].":%'

select count(distinct(hv_ip)) as Count from hit_visit where (1) and hv_set = 'Visit' and hv_datetime like '% ".$Row[0]['Times'].":%'

select count(*) as Count from hit_visit where (1) and hv_set = 'Purchase' and hv_datetime like '% ".$Row[0]['Times'].":%'

select count(*) as Count from hit_visit where (1) and hv_set = 'Put' and hv_datetime like '% ".$Row[0]['Times'].":%'

select count(*) as Count from hit_visit where (1) and hv_set = 'Attention' and hv_datetime like '% ".$Row[0]['Times'].":%'

 

이런 방식으로 불러오고 있습니다.

그런데 이용자가 많아지다보니 속도부분에서 너무 오래 걸리게 되더라구요..

혹시 한번에 처리 할 수 있는 방법은 없을까요?

 

간단한 예제 부탁드립니다.

 

그리고 감사합니다.^^

|

댓글 6개

select
(select count(*) as Count from hit_visit where (1) and hv_set = 'Visit' and hv_datetime like '% ".$Row[0]['Times'].":%' ) as hit_visit1
(select count(distinct(hv_ip)) as Count from hit_visit where (1) and hv_set = 'Visit' and hv_datetime like '% ".$Row[0]['Times'].":%' ) as hit_visit2
(select count(*) as Count from hit_visit where (1) and hv_set = 'Purchase' and hv_datetime like '% ".$Row[0]['Times'].":%' ) as hit_visit3
(select count(*) as Count from hit_visit where (1) and hv_set = 'Put' and hv_datetime like '% ".$Row[0]['Times'].":%' ) as hit_visit1
(select count(*) as Count from hit_visit where (1) and hv_set = 'Attention' and hv_datetime like '% ".$Row[0]['Times'].":%' ) as hit_visit4

이런식으로 해서

hit_visit1 ~ hit_visit4 까지 한번 에 가지오 올수 있습니다.
그리고 데이터 양이 많아서 속도가 느리면요..조건걸럼에다가 index를 걸어주시면 속도가 훨씬 빨라집니다.
답변 감사합니다.
그런데 ㅠㅠ 실행이 안되네요.. ㅠㅠ찡

$Select = "
select
(select count(*) as Count from hit_visit where (1) and hv_set = 'Visit' and hv_datetime like '% 05:%' ) as hit_visit1
(select count(distinct(hv_ip)) as Count from hit_visit where (1) and hv_set = 'Visit' and hv_datetime like '% 05:%' ) as hit_visit2
(select count(*) as Count from hit_visit where (1) and hv_set = 'Purchase' and hv_datetime like '% 05:%' ) as hit_visit3
(select count(*) as Count from hit_visit where (1) and hv_set = 'Put' and hv_datetime like '% 05:%' ) as hit_visit1
(select count(*) as Count from hit_visit where (1) and hv_set = 'Attention' and hv_datetime like '% 05:%' ) as hit_visit4
";
$Query = sql_query($Select);
while($Row = sql_fetch_array($Query)){
print_r($Row);
echo "<br/>";
}
like 사용시에 times를 계속 조회하셔야 하는 사항이면 빨리질수 없습니다.
윗 분님의 설명대로
index를 걸어도 도움은 됩니다만
약효는 금방 떨어질듯 합니다.

참고로 count(*) 보다 특정 컬럼 한개 예를들어 select count(no) 와 같이 처리하시는게 속도에 도움이됩니다.
count(*) 이게 더빠르지 않나요? 기억이 가물가물하지만 이게 count(*) 더빠르다는 실험했다는 분이 있으신데 아 찾아보니 여기 결론이 있네요 http://nampoong.tistory.com/96
아.. 그렇군요
저도 다시 잘 기억하겟습니다. 감사합니다.
2017-06-06 (화) 22:26:58
ㅡ_-)=b
댓글을 작성하시려면 로그인이 필요합니다.

토크

3,606건

오픈소스 관련 다양한 이야기를 자유롭게 나눠요

+
제목 글쓴이 날짜 조회
18-05-18 조회 3,377
18-05-11 조회 3,745
18-05-10 조회 3,571
18-02-26 조회 3,821
18-02-23 조회 3,089
18-02-03 조회 2,702
18-01-19 조회 3,097
17-12-26 조회 3,420
17-10-29 조회 4,249
17-09-16 조회 5,596
17-08-17 조회 5,705
17-08-17 조회 4,045
17-07-03 조회 3,624
17-07-03 조회 4,638
17-07-01 조회 4,485
17-06-30 조회 5,179
17-06-22 조회 3,597
17-06-16 조회 3,274
17-06-15 조회 3,706
17-06-09 조회 3,388
17-06-07 조회 3,512
17-05-25 조회 3,609
17-05-15 조회 1,913
17-05-15 조회 2,996
17-05-11 조회 2,676
17-04-28 조회 3,036
17-04-23 조회 2,387
17-04-12 조회 2,265
17-03-29 조회 3,821
17-03-13 조회 2,761