假如有如下的题目:
要求建立一个关于餐馆的关系模式,包括如下信息:餐馆的位置,风味(如中国风味),价格档次(高档,中等)。
如果要求查询一个餐馆:价格中等,提供印度风味,并且离家的距离在5公里范围内。我的疑惑是SQL语句中,好像不支持开方这样的运算吧?如何来实现距离呢?我的设计是设置两个属性:X,Y坐标。
数据库刚入门,请大家指点迷津。详细点更好哦,非常感谢!
要求建立一个关于餐馆的关系模式,包括如下信息:餐馆的位置,风味(如中国风味),价格档次(高档,中等)。
如果要求查询一个餐馆:价格中等,提供印度风味,并且离家的距离在5公里范围内。我的疑惑是SQL语句中,好像不支持开方这样的运算吧?如何来实现距离呢?我的设计是设置两个属性:X,Y坐标。
数据库刚入门,请大家指点迷津。详细点更好哦,非常感谢!
如果是直接距离呢?如果又不是直接距离怎么算呢?
对这方面我也不清楚,数据库就刚入门。
GIS方面的距离应该是算的直接距离吧?
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.
以上的原题。我对这个题目蛮感兴趣,我是学交通方面的。
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