两个 table 一个包含记录和第二个包含位置我想显示第一个 table 记录而不加入
Two tables one contain records and second conatain location i want to show first table record with out join
我正在处理 两个 table 包含记录;一个是管理员 table,其中包含所有详细信息,第二个是商店的位置,首先我想检查纬度和经度并从 shop_location 获得结果它工作正常,然后,我想检查正在营业的商店的状态并显示结果
这是我的 MYSQL QUERY,效果很好
SELECT DISTINCT s_number,radious, ( 3959 * ACOS( COS( RADIANS(
latitude ) ) * COS( RADIANS( "33.5967558" ) ) * COS( RADIANS(
"73.3869814" ) - RADIANS( longitude ) ) + SIN( RADIANS( latitude
) ) * SIN( RADIANS("33.5967558" ) ) ) ) AS distance FROM
Shop_Location HAVING distance <= radius/1000 ORDER BY distance
ASC
这是我的第二个问题
SELECT * from Admins WHERE shopstatus='ON'
两个 table 中的电话号码相同但不是唯一的我想从 shop_location 查询中获取结果,然后检查商店状态 (ON) 显示结果。
我想用Query解决
假设两个表都链接到“s_number”(店号),您可以尝试以下SQL
SELECT DISTINCT Shop_Location.s_number,radious, ( 3959 * ACOS( COS( RADIANS(
latitude ) ) * COS( RADIANS( "33.5967558" ) ) * COS( RADIANS(
"73.3869814" ) - RADIANS( longitude ) ) + SIN( RADIANS( latitude
) ) * SIN( RADIANS("33.5967558" ) ) ) ) AS distance FROM
Shop_Location, admins where
Shop_Location.s_number=admins.s_number and admins.shopstatus='ON'
HAVING distance <= radius/1000 ORDER BY distance
ASC
可能是这样的:
SELECT DISTINCT
Shop_location.s_number,
Shop_location.radious,
(
3959 * ACOS(
COS(RADIANS(latitude)) * COS(RADIANS("33.5967558")) * COS(
RADIANS("73.3869814") - RADIANS(Shop_location.longitude)
) + SIN(
RADIANS(Shop_location.latitude)
) * SIN(RADIANS("33.5967558"))
)
) AS DISTANCE,
Admins.shopstatus
FROM
Shop_Location
LEFT JOIN
Admins
ON
Admins.s_number = Shop_location.s_number
HAVING
DISTANCE <= radius / 1000
ORDER BY
DISTANCE ASC
这是正确的答案
SELECT DISTINCT
Admins.email,Admins.address,Admins.adminname,
Admins.diliveryfee,Admins.endingtime,Admins.minorder
,Admins.name,Admins.password,Admins.shopimage,
Admins.shopmessage,Admins.phonenumber,
Admins.shopname,Admins.shopstatus FROM (
SELECT Admins.email,Admins.address,Admins.adminname,Admins.diliveryfee,Admins.endingtime,Admins.minorder,Admins.name,Admins.password,Admins.shopimage,Admins.shopmessage,Admins.phonenumber,Admins.shopname,Admins.shopstatus,Shop_Location.radious AS shopLocationRadius, ( 6371 * ACOS( COS(
RADIANS( latitude ) ) * COS( RADIANS( "33.5967558" ) ) *
COS( RADIANS( "73.3869814" ) - RADIANS( longitude ) ) +
SIN( RADIANS( latitude ) ) * SIN(
RADIANS("33.5967558" )
) ) ) AS distance FROM Shop_Location INNER JOIN
Admins ON
(Admins.phonenumber = Shop_Location.s_number) WHERE
Admins.shopstatus='ON' HAVING distance <= radious/1000
ORDER BY distance ASC)
AS Admins
我正在处理 两个 table 包含记录;一个是管理员 table,其中包含所有详细信息,第二个是商店的位置,首先我想检查纬度和经度并从 shop_location 获得结果它工作正常,然后,我想检查正在营业的商店的状态并显示结果
这是我的 MYSQL QUERY,效果很好
SELECT DISTINCT s_number,radious, ( 3959 * ACOS( COS( RADIANS(
latitude ) ) * COS( RADIANS( "33.5967558" ) ) * COS( RADIANS(
"73.3869814" ) - RADIANS( longitude ) ) + SIN( RADIANS( latitude
) ) * SIN( RADIANS("33.5967558" ) ) ) ) AS distance FROM
Shop_Location HAVING distance <= radius/1000 ORDER BY distance
ASC
这是我的第二个问题
SELECT * from Admins WHERE shopstatus='ON'
两个 table 中的电话号码相同但不是唯一的我想从 shop_location 查询中获取结果,然后检查商店状态 (ON) 显示结果。
我想用Query解决
假设两个表都链接到“s_number”(店号),您可以尝试以下SQL
SELECT DISTINCT Shop_Location.s_number,radious, ( 3959 * ACOS( COS( RADIANS(
latitude ) ) * COS( RADIANS( "33.5967558" ) ) * COS( RADIANS(
"73.3869814" ) - RADIANS( longitude ) ) + SIN( RADIANS( latitude
) ) * SIN( RADIANS("33.5967558" ) ) ) ) AS distance FROM
Shop_Location, admins where
Shop_Location.s_number=admins.s_number and admins.shopstatus='ON'
HAVING distance <= radius/1000 ORDER BY distance
ASC
可能是这样的:
SELECT DISTINCT
Shop_location.s_number,
Shop_location.radious,
(
3959 * ACOS(
COS(RADIANS(latitude)) * COS(RADIANS("33.5967558")) * COS(
RADIANS("73.3869814") - RADIANS(Shop_location.longitude)
) + SIN(
RADIANS(Shop_location.latitude)
) * SIN(RADIANS("33.5967558"))
)
) AS DISTANCE,
Admins.shopstatus
FROM
Shop_Location
LEFT JOIN
Admins
ON
Admins.s_number = Shop_location.s_number
HAVING
DISTANCE <= radius / 1000
ORDER BY
DISTANCE ASC
这是正确的答案
SELECT DISTINCT
Admins.email,Admins.address,Admins.adminname,
Admins.diliveryfee,Admins.endingtime,Admins.minorder
,Admins.name,Admins.password,Admins.shopimage,
Admins.shopmessage,Admins.phonenumber,
Admins.shopname,Admins.shopstatus FROM (
SELECT Admins.email,Admins.address,Admins.adminname,Admins.diliveryfee,Admins.endingtime,Admins.minorder,Admins.name,Admins.password,Admins.shopimage,Admins.shopmessage,Admins.phonenumber,Admins.shopname,Admins.shopstatus,Shop_Location.radious AS shopLocationRadius, ( 6371 * ACOS( COS(
RADIANS( latitude ) ) * COS( RADIANS( "33.5967558" ) ) *
COS( RADIANS( "73.3869814" ) - RADIANS( longitude ) ) +
SIN( RADIANS( latitude ) ) * SIN(
RADIANS("33.5967558" )
) ) ) AS distance FROM Shop_Location INNER JOIN
Admins ON
(Admins.phonenumber = Shop_Location.s_number) WHERE
Admins.shopstatus='ON' HAVING distance <= radious/1000
ORDER BY distance ASC)
AS Admins