作者:woodburger_821 | 来源:互联网 | 2023-05-18 09:09
Imeditingastoredproceduretogetthedistanceandthesortitfromthat.ThequeryImusingis
I'm editing a stored procedure to get the distance and the sort it from that. The query I'm using is working on another stored procedure.
我正在编辑存储过程以获取距离并从中进行排序。我正在使用的查询正在处理另一个存储过程。
SELECT *,
(
ACOS( COS( RADIANS( 41.993000000 ) )
* COS( RADIANS( u.real_users_lat ) )
* COS( RADIANS( u.real_users_long ) - RADIANS( -87.696207000 ) )
+ SIN( RADIANS( 41.993000000 ) )
* SIN( RADIANS( u.real_users_lat ) )
)
* 6371
) AS distance_in_km
FROM products
LEFT JOIN users u on u.id = products.created_by
LEFT JOIN product_categories on product_categories.product_id = products.id
WHERE products.starting_bid <= @price and product_categories.category_id = @category_id
ORDER BY
CASE WHEN @sort_direction = 'asc' THEN products.date_created END asc,
CASE WHEN @sort_direction = 'desc' THEN products.date_created END desc,
CASE WHEN @sort_distance = 'nearest' THEN distance_in_km END desc,
CASE WHEN @sort_distance = 'farthest' THEN distance_in_km END asc
END
The error is Invalid column name 'distance_in_km'.
but on my other stored procedure here it is working.
错误是无效的列名称'distance_in_km'。但在我的其他存储过程中它正在工作。
SELECT
distinct Products.*,
(
SELECT Count(bids.id)
FROM bids
Where bids.product_id = products.id
) as bid_count ,
(
SELECT firebase_user_id
FROM Users
Where Users.id = created_by
) as seller_firebase_id ,
(
ACOS( COS( RADIANS( 41.993000000 ) )
* COS( RADIANS( u.real_users_lat ) )
* COS( RADIANS( u.real_users_long ) - RADIANS( -87.696207000 ) )
+ SIN( RADIANS( 41.993000000 ) )
* SIN( RADIANS( u.real_users_lat ) )
)
* 6371
) AS distance_in_km
FROM Products
LEFT JOIN areas on areas.id = products.area
LEFT JOIN Product_categories on Product_categories.product_id = products.id
LEFT JOIN Users u on u.id = Products.created_by
WHERE products.status <> 4
ORDER BY distance_in_km DESC
END
Please let me know what I'm doing wrong.
请让我知道我做错了什么。
2 个解决方案