where子句中的列“ date_start”不明确

时间:2019-05-23 10:44:16

标签: mysql

我想选择一些日期,但是我对此有疑问

SELECT DISTINCT `clients_agreements`.`date_start` , `buildings`.`id` ,
    `buildings`.`street` , `buildings`.`street_nr` ,
    `clients`.`building_id` , `clients_agreements`.`user_id`, `clients_agrees_conds`.`user_id`, `clients_agrees_perss`.`client_agreement_id`
FROM `clients_agreements`
LEFT JOIN `buildings`
    On `clients_agreements`.`user_id` = `buildings`.`id`
LEFT JOIN `clients`
    ON `clients`.`building_id` = `buildings`.`id`
LEFT JOIN `clients_agrees_conds`
    ON `clients_agreements`.`user_id` = `clients_agrees_conds`.`user_id`
LEFT JOIN `clients_agrees_perss`
   ON `clients_agrees_conds`.`user_id` = `clients_agrees_perss`.`user_id`
WHERE `date_start` = (CURRENT_DATE)

我收到此错误#1052-where子句中的列“ date_start”不明确

2 个答案:

答案 0 :(得分:0)

Where子句应包含date_start的别名以指向特定的表:

        SELECT DISTINCT `clients_agreements`.`date_start` , `buildings`.`id` , `buildings`.`street` , `buildings`.`street_nr` , `clients`.`building_id` , `clients_agreements`.`user_id`, `clients_agrees_conds`.`user_id`, `clients_agrees_perss`.`client_agreement_id` 
        FROM `clients_agreements` 
        LEFT JOIN `buildings` On `clients_agreements`.`user_id` = `buildings`.`id` 
        LEFT JOIN `clients` ON `clients`.`building_id` = `buildings`.`id` 
        LEFT JOIN `clients_agrees_conds` ON `clients_agreements`.`user_id` = `clients_agrees_conds`.`user_id` 
        LEFT JOIN `clients_agrees_perss` ON `clients_agrees_conds`.`user_id` = `clients_agrees_perss`.`user_id` 
        WHERE `clients_agreements`.`date_start` = (CURRENT_DATE)

答案 1 :(得分:0)

在where子句中,在其旁边添加表名,例如

clients_agreementsdate_start = CURRENT_DATE