Подзапрос об ошибке Java - PullRequest
0 голосов
/ 22 мая 2018

Привет, ребята, я пытался сделать запрос на Java для доступа к данным из базы данных, но при компиляции ошибка синтаксическая ошибка в или около "v" , когда я пытаюсь скомпилировать мой запрос на postgresql, это работаети данные могут показать, но когда я компилирую на затмении, он не может

это запрос

@Override
protected StringBuffer buildQuery(String sql, Object... objects) {
    StringBuffer sbSQL = new StringBuffer("SELECT a.master_user_id, b.name, d.group_name, a.role, "
            + "(SELECT count (v.id) FROM project_member_dtl v "
            + "LEFT JOIN project_timeline p ON v.project_timeline_id = p.id "
            + "LEFT JOIN master_project_dtl j ON p.master_project_dtl_rid = j.rid "
            + "LEFT JOIN master_project aa ON j.master_project_sid = aa.sid "
            + "where ((v.member_plan_date > now()) AND (v.member_real_date IS NULL)) "
            + "AND j.is_freeze = 'n' "
            + "AND p.is_active = 'y' "
            + "AND aa.is_deleted = 'n' "
            + "AND v.master_user_id = a.master_user_id"
            + "AND v.master_role_id = a.master_role_id ) as in_progress, "

            + "(SELECT count (w.id) FROM project_member_dtl w "
            + "LEFT JOIN project_timeline q ON w.project_timeline_id = q.id "
            + "LEFT JOIN master_project_dtl k ON q.master_project_dtl_rid = k.rid "
            + "LEFT JOIN master_project bb ON k.master_project_sid = bb.sid "
            + "where ((w.member_plan_date < now()) "
            + "AND (w.member_real_date IS NULL)) "
            + "AND k.is_freeze = 'n' "
            + "AND q.is_active = 'y' "
            + "AND bb.is_deleted = 'n' "
            + "AND w.master_user_id = a.master_user_id "
            + "AND w.master_role_id = a.master_role_id ) as in_progress_late, "

            + "(SELECT count (x.id) FROM project_member_dtl x "
            + "LEFT JOIN project_timeline r ON x.project_timeline_id = r.id "
            + "LEFT JOIN master_project_dtl l ON r.master_project_dtl_rid = l.rid "
            + "LEFT JOIN master_project cc ON l.master_project_sid = cc.sid "
            + "where (x.member_plan_date IS NULL) "
            + "AND l.is_freeze = 'n' AND r.is_active = 'y' "
            + "AND cc.is_deleted = 'n' "
            + "AND x.master_user_id = a.master_user_id "
            + "AND x.master_role_id = a.master_role_id ) as waiting_list, "

            + "(SELECT count (y.id) FROM project_member_dtl y"
            + "LEFT JOIN project_timeline s ON y.project_timeline_id = s.id "
            + "LEFT JOIN master_project_dtl m ON s.master_project_dtl_rid = m.rid "
            + "LEFT JOIN master_project dd ON m.master_project_sid = dd.sid "
            + "where (y.member_plan_date > y.member_real_date) "
            + "AND m.is_freeze = 'n' AND s.is_active = 'y' "
            + "AND dd.is_deleted = 'n' "
            + "AND y.master_user_id = a.master_user_id "
            + "AND y.master_role_id = a.master_role_id ) as finish_on_time, "

            + "(SELECT count (z.id) FROM project_member_dtl z "
            + "LEFT JOIN project_timeline t ON z.project_timeline_id = t.id"
            + "LEFT JOIN master_project_dtl n ON t.master_project_dtl_rid = n.rid"
            + "LEFT JOIN master_project ee ON n.master_project_sid = ee.sid"
            + "where (z.member_plan_date < z.member_real_date)"
            + "AND n.is_freeze = 'n' AND t.is_active = 'y'"
            + "AND ee.is_deleted = 'n' "
            + "AND z.master_user_id = a.master_user_id "
            + "AND z.master_role_id = a.master_role_id ) as finish_over_time"

            + "FROM project_member_dtl a");

    sbSQL.append("LEFT JOIN master_user b ON a.master_user_id = b.id ");
    sbSQL.append("LEFT JOIN user_group c ON a.master_user_id = c.master_user_id ");
    sbSQL.append("LEFT JOIN master_group d ON c.group_id = d.id  ");

    sbSQL.append(sql);      
    return sbSQL;
}

спасибо

1 Ответ

0 голосов
/ 22 мая 2018

Это опечатка.Обязательно оставляйте пробел в конце каждой строки

+"AND v.master_user_id = a.master_user_id "

В первом запросе вы пропустили пробел

+"AND v.master_user_id = a.master_user_id"
+ "AND v.master_role_id = a.master_role_id ) as in_progress, "

Теперь запрос будет

...AND v.master_user_id = a.master_user_idAND v.master_role_id =....

Движок SQL считает, что a.master_user_idAND является столбцом.Так что следующая v проблема.Вот почему синтаксическая ошибка

в или около "v"

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...