Как вставить динамический параметр в оператор MySQL?

0

Я использую mysql как базу данных, и это запрос

select 
  job_id, 
  area_set, 
  area_subset, 
  worker_type, 
  job_posting_name, 
  job_location, 
  start_date, 
  end_date, 
  description, 
  is_template, 
  template_name, 
  is_draft, 
  no_of_post, 
  is_open, 
  pay_rate, 
  is_completed, 
  create_date, 
  contractor_company_name, 
  jobs.user_id 
from 
  jobs, contractor_company 
where job_id not in (select job_id from job_response where job_response.user_id = 864) 
  and is_template in (0,1) 
  and is_draft in (0,0) 
  and is_open in (1,1) 
  and is_completed in (0,0) 
  and contractor_company.contractor_company_id = (select contractor_company_id from  contractor_survey_question 
    where contractor_survey_question.user_id = jobs.user_id) 
    and jobs.user_id IN ( select user.user_id from user where user.phone_country_code =(select user.phone_country_code from user 
      where user.user_id=864 )) and area_set = 10 and area_subset in(78,79)
order by create_date desc; 

Здесь в area_subset может быть разное количество параметров.

И я вызываю это утверждение из js-адаптера, как

select 
  job_id, 
  worker_type, 
  job_posting_name, 
  job_location, 
  start_date, 
  end_date, 
  description, 
  is_template, 
  template_name, 
  is_draft, 
  no_of_post, 
  is_open,
  pay_rate, 
  is_completed, 
  create_date,
  contractor_company_name,
  jobs.user_id 
from
  jobs, contractor_company 
where job_id not in (select job_id from  job_response where job_response.user_id = ?) 
  and is_template in (?,?) 
  and is_draft in (?,?) 
  and is_open in (?,?) 
  and is_completed in (?,?) 
  and contractor_company.contractor_company_id = (select  contractor_company_id from  contractor_survey_question 
    where contractor_survey_question.user_id = jobs.user_id) 
    and jobs.user_id IN ( select user.user_id from user 
      where user.phone_country_code =(select user.phone_country_code from user 
        where user.user_id=? ))  and area_set = ? and area_subset in(?,?) 
order by create_date desc; 

например, в area_subset может быть более двух параметров, то как я могу передать этот запрос.

Просьба помочь

  • 0
    Скажем, у меня есть area_subset (10,78,79), тогда как я могу добавить динамический '?' в запросе, как area_subset (?,?,?)
Теги:

1 ответ

1
CREATE DEFINER='root'@'localhost' PROCEDURE 'test'(input VARCHAR(15))
BEGIN
SET @input = input;

if @input="asc" then
    SET @sort = " order by ActivityLogKey asc";
elseif @input = "desc" then
    SET @sort = " order by ActivityLogKey desc";
else
    SET @sort ="";
end if;

SET @query = CONCAT('select * from activitylog ',@sort,' limit 0, 5');

PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

END
  • 0
    Я не устанавливаю лимит. это похоже на то, что если в этом столбце 78 или 79, или 10, или любая другая комбинация, тогда будут выбраны строки.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню