Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding 2 floats as strings 2

Status
Not open for further replies.

harmmeijer

Programmer
Mar 1, 2001
869
CN
Hello all and thank you for reading my question.

I have 2 float fields lat and long and want to have the rows collapse where both lat and long are the same.
I want to add the lat and long as strings and group them by that

select lat, long, count(lat + ' - ' + long) from ...
group by lat + ' - ' + long

since lat and long are both float the + ' - ' + does not add them as strings, looked at the documentation but could not find any method to add numbers as strings, in sql server I could use something like ctype I think but there seem to be no equivalent in mysql.

Anybody got some tips on how to get the rows grouped only if both lat and long is the same?

Greetings, Harm Meijer
 
Well here is a second question:
How do I add strings in mysql sql expression?

select 'this' + ' will ' + ' be 0'
ends up giving me the value:
0

Greetings, Harm Meijer
 
To concatentate strings, use the CONCAT function:
CONCAT(str1,str2,str3)
I'm not clear what you're getting at regarding the grouping. Maybe you could explain a bit more, with some example input and output.
 
Hi, thanks for your reply.
Don't need the 2 floats as string and add them since I can just do it like this:

SELECT latitude, longitude, count( latitude )
FROM users
GROUP BY latitude, longitude
HAVING count( latitude ) > 1

They will not be grouped unless both latitude and longitude are the same.

Still wonder how to concat numbers.

If I wish
select 1 + 2 + 3
to be:
123
instead of 6 I need to 1,2 and 3 to be strings. But there seems to be no way in mysql to cast numbers to strings

Greetings, Harm Meijer
 
you can use CAST if you want to, but you don't have to, mysql will "silently" perform the conversion for you --

CONCAT(1,2,3)

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top