假如有如下的题目:
要求建立一个关于餐馆的关系模式,包括如下信息:餐馆的位置,风味(如中国风味),价格档次(高档,中等)。
如果要求查询一个餐馆:价格中等,提供印度风味,并且离家的距离在5公里范围内。我的疑惑是SQL语句中,好像不支持开方这样的运算吧?如何来实现距离呢?我的设计是设置两个属性:X,Y坐标。
数据库刚入门,请大家指点迷津。详细点更好哦,非常感谢!

解决方案 »

  1.   

    oracle spatial因为涉及到直线距离和经纬度坐标的转化,而且还要参照你的空间数据坐标系,所以单单用sql语句计算的是不准确的。
      

  2.   

    先非常感谢大家的关注!
    如果是直接距离呢?如果又不是直接距离怎么算呢?
    对这方面我也不清楚,数据库就刚入门。
    GIS方面的距离应该是算的直接距离吧?
      

  3.   

    你需要用专门的gis引擎来做..
      

  4.   

    假如就只要建立表呢?怎么建立?这是我作业中的一个题目。主要侧重在数据库的建立和SQL语句的实现查询。
      

  5.   

    Study the support for spatial data offered by the database system that you use,
    and implement the following:
    a. A schema to represent the geographic location of restaurants along with
    features such as the cuisine served at the restaurant and the level of expensiveness.
    b. A query to find moderately priced restaurants that serve Indian food and
    are within 5 miles of your house (assume any location for your house).
    c. A query to find for each restaurant the distance from the nearest restaurant
    serving the same cuisine and with the same level of expensiveness.
    以上的原题。我对这个题目蛮感兴趣,我是学交通方面的。
      

  6.   

    这个作业也太不专业了..假设一个场景,平面坐标系(一般都是球面的投影坐标系),原点为火车站,所以点都已火车站为参考点,x,y是离火车站的距离create table geom(name varchar(100),x float ,y float)insert into geom select '火车站',0,0
    insert into geom select '麦当劳',200,100
    insert into geom select '肯德基',300,300
    insert into geom select '印度阿三',100,100
    gocreate function get_distance(@x1 float,@y1 float,@x2 float,@y2 float)
    returns float
    begin
    declare @ret float
    select @ret=power(power(@x1-@x2,2)+power(@y1-@y2,2),0.5)
    return @ret
    end
    go
    --离火车站的距离
    select *,dbo.get_distance(0,0,x,y) from geom   
    --离火车站不超过300米的
    select *from geom  where dbo.get_distance(0,0,x,y) <=300--离火车站不超过300米的印度饭店
    select *from geom  where dbo.get_distance(0,0,x,y) <=300 and name like '%印度%'drop table geom
    drop function get_distance
      

  7.   

    你要是真的对这个题目感兴趣,就去学oracle spatail和专业gis开发的知识吧
      

  8.   

    非常感谢诸位的关注,特别感谢JINJAZZ。