【问题标题】:Display items by location. Mysql Select按位置显示项目。 mysql选择
【发布时间】:2010-09-22 01:37:46
【问题描述】:

我有两个 MySQL 表,“位置”和项目“:

locations
  `id` `name` `address` `latitude` `longitude`

现在我使用 MySQL SELECT,它允许用户输入他们的纬度和经度,它会按距离对位置进行排序。效果很好。

现在我有一个项目列表:

items
  `id` `location` `title` `description` `display`

现在,如果该项目的display = true,我想显示每个位置的项目。我希望这是有效的,因为有些位置没有任何项目,或者没有设置为 display = true 的项目。

【问题讨论】:

  • 按距离排序的查询是什么?

标签: php mysql select


【解决方案1】:

此查询将为您提供按位置排序的项目列表

SELECT items.*, locations.* FROM items JOIN locations ON locations.id = items.location WHERE items.display = 'true' ORDER BY locations.id;

【讨论】:

    【解决方案2】:
    select location.name, items.title, items.description
    from location, items
    where location.id = items.location
    and items.display = 'true'
    order by location.name
    

    我认为这可以满足您的需求,但是如果没有其他信息,就很难判断。例如,items 表中的 location 字段是否实际上是 location 表的外键(从上下文中看不出来)。

    【讨论】:

      猜你喜欢
      • 2021-02-07
      • 2012-07-07
      • 1970-01-01
      • 2021-01-20
      • 1970-01-01
      • 1970-01-01
      • 2017-05-01
      • 2018-01-22
      • 2011-10-08
      相关资源
      最近更新 更多