错误代码:1055。SELECT列表的表达式#2不在GROUP BY中

时间:2019-07-10 08:25:56

标签: mysql group-by

我想知道'member_seq'的计数以匹配'R_INFO.nick_name'的值。

如何获取计数数据?

SQL

SELECT
    nick_name,
    REPORT.seq_no,
    report_type,
    report_item,
    contents,
    DATE_FORMAT(report_dt, '%Y-%m-%d %H:%i:%s') AS report_dt,
    REPORT.status,
    question,
    E_INFO.status AS game_status,
    entry_fee,
    REPORT.game_seq,
    Count(member_seq)
FROM
    REPORT
LEFT JOIN R_INFO ON
    REPORT.member_seq = R_INFO.seq_no
LEFT JOIN E_INFO ON
    REPORT.game_seq = E_INFO.seq_no
GROUP BY R_INFO.nick_name;

2 个答案:

答案 0 :(得分:0)

我不能保证您的JOIN逻辑是否正确,但是要纠正错误,如其文字所示,您需要删除所有未汇总或分组的列。所有这些:

REPORT.seq_no,
report_type,
report_item,
contents,
DATE_FORMAT(report_dt, '%Y-%m-%d %H:%i:%s') AS report_dt,
REPORT.status,
question,
E_INFO.status AS game_status,
entry_fee,
REPORT.game_seq

查询将变为:

SELECT nick_name, Count(member_seq)
FROM REPORT
LEFT JOIN R_INFO ON REPORT.member_seq = R_INFO.seq_no
LEFT JOIN E_INFO ON REPORT.game_seq = E_INFO.seq_no
GROUP BY R_INFO.nick_name;

答案 1 :(得分:0)

我因为英语不好而感到困惑。我很努力地找出并以这种方式解决。

SELECT
    nick_name,
    REPORT.seq_no,
    report_type,
    report_item,
    contents,
    DATE_FORMAT(report_dt, '%Y-%m-%d %H:%i:%s') AS report_dt,
    REPORT.status,
    question,
    E_INFO.status AS game_status,
    entry_fee,
    REPORT.game_seq,
    (SELECT COUNT(member_seq) REPORT WHERE member_seq = R_INFO.seq_no) AS count_member,
FROM
    REPORT
LEFT JOIN R_INFO ON
    REPORT.member_seq = R_INFO.seq_no
LEFT JOIN E_INFO ON
    REPORT.game_seq = E_INFO.seq_no