0

私がこのSQLクエリを持っていると仮定しましょう

SELECT max(times_viewed) as m, member_id, (select count(viewed_url) from exp_member_page_tracker  where member_id=mpv.member_id)
FROM `exp_member_page_tracker` mpv
group by member_id

すべての結果を数える必要があります。私はこのようにそれをします

SELECT count(member_id) from ( SELECT max(times_viewed) as m, member_id, (select count(viewed_url) from exp_member_page_tracker where member_id=mpv.member_id)
FROM `exp_member_page_tracker` mpv
group by member_id) as m2

しかし、それがどのように効率的かはわかりません。結果を最良の方法で数える方法を教えてください。

ありがとう

4

1 に答える 1

1

あなたのサブクエリについて、私は何かが欠けていますか、これはより効率的な同じ結果ではありませんか?sqlfiddleで試してみました:

http://sqlfiddle.com/#!2/a03cf/9

あなたの:

SELECT member_id, max(times_viewed) as max_times_viewed 
, (select count(viewed_url) from exp_member_page_tracker  where member_id=mpv.member_id) as countOfViewedUrl
FROM `exp_member_page_tracker` mpv
group by member_id;

別:

SELECT member_id, max(times_viewed) as max_times_viewed
, count(viewed_url) as countOfViewedUrl
FROM `exp_member_page_tracker` mpv
group by member_id;
于 2012-04-14T20:44:27.767 に答える