我有以下SQL语句:
SELECT Distinct(Venue_Name), Count(*) as `num1`
FROM venuetagview
INNER JOIN
(
SELECT Tag,COUNT(*) AS `num`
FROM usertags
WHERE UserID=4
GROUP BY Tag
ORDER BY `num` DESC
) as a
ON venuetagview.Tag=a.Tag
GROUP BY Venue_Name
ORDER BY `num1` DESC
我正在尝试使用venuetagview表中的纬度/经度为其添加“距离”计算。我试过这个:
SELECT
( 6371
* acos( cos( radians(51.529099) )
* cos( radians( Venue_Latitude ) )
* cos( radians( Venue_Longitude )
- radians(-0.084981) )
+ sin( radians(51.529099) )
* sin( radians( Venue_Latitude ) ) ) ) AS distance,
Distinct(Venue_Name),
Count(*) as `num1`
FROM venuetagview
INNER JOIN
(
SELECT Tag,
COUNT(*) AS `num`
FROM usertags
WHERE UserID=4
GROUP BY Tag
ORDER BY `num` DESC
) as a
ON venuetagview.Tag=a.Tag
GROUP BY Venue_Name
ORDER BY `num1` DESC
但是我在使用它时遇到错误。
答案 0 :(得分:0)
我发布的查询仅显示
distinct
是关键作品,应该像distinct column_name
SELECT Distinct (Venue_Name)
应该是SELECT Venue_Name
或
SELECT Distinct Venue_Name
答案 1 :(得分:0)
如草莓所述,DISTINCT解决了这个问题:
SELECT
{NUM1 {1}} {NUM {1}} {NUM {1}}
( 6371 * acos( cos( radians(51.529099) )
* cos( radians( Venue_Latitude ) )
* cos( radians( Venue_Longitude )
- radians(-0.084981) )
+ sin( radians(51.529099) )
* sin( radians( Venue_Latitude ) ) ) ) AS distance,
Venue_Name,
Count(*) as