0

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

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' 不明确

4

2 回答 2

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)
于 2019-05-23T10:47:56.053 回答
0

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

clients_agreements. date_start= CURRENT_DATE

于 2019-05-23T10:49:34.060 回答