代码之家  ›  专栏  ›  技术社区  ›  Jesse Bunch

SQL查询问题

  •  2
  • Jesse Bunch  · 技术社区  · 16 年前

    我已经做了一段时间了。基本上,我需要添加一个派生列来计算数据库中一个日志条目的点击量。问题是,点击量被合计,只在第一条记录上显示。有什么想法吗?我已经鼓足了我所说的问题的勇气。查询如下:

    SELECT DISTINCT(t.entry_id), 
        exp_categories.rank, 
        **exp_hits.hits,** 
        t.entry_id, 
        t.weblog_id, 
        t.forum_topic_id, 
        t.author_id, 
        t.ip_address, 
        t.title, 
        t.url_title, 
        t.status, 
        t.dst_enabled, 
        t.view_count_one, 
        t.view_count_two, 
        t.view_count_three, 
        t.view_count_four, 
        t.allow_comments, 
        t.comment_expiration_date, 
        t.allow_trackbacks, 
        t.sticky, 
        t.entry_date, 
        t.year, 
        t.month, 
        t.day, 
        t.entry_date, 
        t.edit_date, 
        t.expiration_date, 
        t.recent_comment_date, 
        t.comment_total, 
        t.trackback_total, 
        t.sent_trackbacks, 
        t.recent_trackback_date, 
        t.site_id as entry_site_id, 
        w.blog_title, 
        w.blog_name, 
        w.search_results_url, 
        w.search_excerpt, 
        w.blog_url, 
        w.comment_url, 
        w.tb_return_url, 
        w.comment_moderate, 
        w.weblog_html_formatting, 
        w.weblog_allow_img_urls, 
        w.weblog_auto_link_urls, 
        w.enable_trackbacks, 
        w.trackback_use_url_title, 
        w.trackback_field, 
        w.trackback_use_captcha, 
        w.trackback_system_enabled, 
        m.username, 
        m.email, 
        m.url, 
        m.screen_name, 
        m.location, 
        m.occupation, 
        m.interests, 
        m.aol_im, 
        m.yahoo_im, 
        m.msn_im, 
        m.icq, 
        m.signature, 
        m.sig_img_filename, 
        m.sig_img_width, 
        m.sig_img_height, 
        m.avatar_filename, 
        m.avatar_width, 
        m.avatar_height, 
        m.photo_filename, 
        m.photo_width, 
        m.photo_height, 
        m.group_id, 
        m.member_id, 
        m.bday_d, 
        m.bday_m, 
        m.bday_y, 
        m.bio, 
        md.*, 
        wd.* 
    FROM exp_weblog_titles AS t 
        LEFT JOIN exp_weblogs AS w ON t.weblog_id = w.weblog_id 
        LEFT JOIN exp_weblog_data AS wd ON t.entry_id = wd.entry_id 
        LEFT JOIN exp_members AS m ON m.member_id = t.author_id 
        LEFT JOIN exp_member_data AS md ON md.member_id = m.member_id 
        LEFT JOIN exp_category_posts ON wd.entry_id = exp_category_posts.entry_id 
        **LEFT JOIN
        (
            SELECT COUNT(*) AS hits, exp_hits.entry_id FROM exp_hits ORDER BY exp_hits.entry_id
        ) exp_hits ON t.entry_id = exp_hits.entry_id**
        LEFT JOIN 
        ( 
            SELECT exp_categories.cat_id, cat_name as rank 
            FROM exp_categories 
            WHERE exp_categories.group_id = '9' 
        ) exp_categories ON exp_categories.cat_id = exp_category_posts.cat_id 
    WHERE t.entry_id IN (2,3,4) ORDER BY exp_categories.rank DESC, **exp_hits.hits DESC**, entry_date desc
    
    2 回复  |  直到 16 年前
        1
  •  3
  •   Adriaan Stander    16 年前

    尝试将子选择更改为

    SELECT COUNT(*) AS hits, 
        exp_hits.entry_id 
    FROM exp_hits 
    GROUP BY exp_hits.entry_id
    
        2
  •  0
  •   Ty W    16 年前

    出于好奇心,您的点击功能是不能用数据库中已经存在且由expressionEngine模板标记支持的“查看计数”字段来完成的吗?

    推荐文章