Jump to content

COUNT's gone weird


rarebit

Recommended Posts

Hi,

 

From a number of search queries a statement is made and used as a COUNT, however for some reason today it's gone wrong, but I can't see why...

 

SELECT latitude, longitude, ( 60 * 1.1515 * DEGREES(ACOS(SIN(RADIANS(53.3540)) * SIN(RADIANS(latitude)) + COS(RADIANS(53.3540)) * COS(RADIANS(latitude)) * COS(RADIANS(-1.4890-longitude)))) ) as dist, 
COUNT(*) as num 
FROM basic 
LEFT JOIN pcodes ON pcodes.postcode = basic.postcode 
GROUP BY basic.id 
HAVING ( dist <= 200 )

 

num = 1

 

but it shouldn't!

 

Any ideas? ? ?

 

p.s. I've also tried selecting 'basic.id', to no avail...

Link to comment
https://forums.phpfreaks.com/topic/109926-counts-gone-weird/
Share on other sites

Yes the id's are unique, but I don't really want to return the full list (even if only id's) and then count them because it's wasteful (there should be at least 2k+ entries) on the mysql network and probably quicker to do it with mysql.

 

Here's how i've altered it for the counting statement (there is also a more complex selecting statement (which still works!) ):

SELECT latitude, longitude, basic.id, COUNT(*) as num 
FROM basic 
LEFT JOIN pcodes ON pcodes.postcode = basic.postcode 
WHERE ( ( 60 * 1.1515 * DEGREES(ACOS(SIN(RADIANS(53.3540)) * SIN(RADIANS(latitude)) + COS(RADIANS(53.3540)) * COS(RADIANS(latitude)) * COS(RADIANS(-1.4890-longitude)))) ) <= 200 ) 
GROUP BY basic.id

Link to comment
https://forums.phpfreaks.com/topic/109926-counts-gone-weird/#findComment-564139
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.