无法使用内部联接创建查询

时间:2017-06-12 09:09:03

标签: mysql

 CREATE VIEW `list_of_parts` 
     AS select `a`.`id` AS `id`,
    `a`.`types` AS `types`,
    `a`.`clerk_id` AS `clerk_id`,
    `a`.`clerk_name` AS `clerk_name`,
    `a`.`post_id` AS `post_id`,
    ifnull(`b`.`shop_id`,`a`.`id`) AS `my_id`,
    `c`.`status` AS `status`,
    `c`.`created` AS `created`,
    `c`.`modified` AS `modified` from ((`main_store` `a` 
left join `main_store_ids` `b` on((`a`.`id` = `b`.`shop_id`))) 
left join `sub_shop` `c` on((ifnull(`b`.`shop_id`,`a`.`id`) = `c`.`id`)))

我想创建一个查询,它将使用subshop表中的clerk_id获取上述数据。如果子商店的clerk_id等同于main_stores clerk_id,我想获取数据。但我无法解决如何用上面的代码完成它。一些样品会很棒。我很乐意听到你的消息!

    a = main_store  
    b = main_store_ids
    c = sub_shop  ← this table contains a field named clerk_id

0 个答案:

没有答案