d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Iso Mysql Help > Totally Stuck 100 Fg
Add Reply New Topic New Poll
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Mar 10 2016 06:17am
Code
MariaDB [junk]> select avg(lat) `Average lat` from (select max(lat) `lat` from zips where state_prefix like 'MO') x natural join (select min(lat) `lat` from zips where state_prefix like 'MO') y;
[/URL]+-------------+
| Average lat |
+-------------+
| NULL |
+-------------+
1 row in set (0.08 sec)


i dont understand why this is null

what i'm trying to do is figure out the (max latitude + min latitude) / 2

table is zips

field is lat

i need to select take the upper half of the "lat"s but i cant figure out how to find the middle lattitude, as you may know with mysql i can't take the nice easy oracle path and avg(max(lat),min(lat))

This post was edited by Ideophobe on Mar 10 2016 06:21am
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Mar 10 2016 06:20am
MariaDB [junk]> select avg(b.asdf) from ((select max(lat) asdf from zips where state_prefix like 'MO') a) inner join ((select min(lat) asdf from zips where state_prefix like 'MO') b);
+--------------------+
| avg(b.asdf) |
+--------------------+
| 36.040000915527344 |
+--------------------+
1 row in set (0.07 sec)



MariaDB [junk]> select avg(a.asdf) from ((select max(lat) asdf from zips where state_prefix like 'MO') a) inner join ((select min(lat) asdf from zips where state_prefix like 'MO') b);
+--------------------+
| avg(a.asdf) |
+--------------------+
| 40.560001373291016 |
+--------------------+
1 row in set (0.07 sec)


I DONT UNDERSTAND THIS SHIT'S DRIVING ME CRAZY
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Mar 10 2016 06:23am
Code
MariaDB [junk]> select (b.asdf + a.asdf)/2 from ((select max(lat) asdf from zips where state_prefix like 'MO') a) inner join ((select min(lat) asdf from zips where state_prefix like 'MO') b);
+---------------------+
| (b.asdf + a.asdf)/2 |
+---------------------+
| 38.30000114440918 |
+---------------------+
1 row in set (0.08 sec)


nevermind i guess this will work looking at it on the webpage helped
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 10 2016 11:26am
If you're using avg,I assume you wanted to union the max and min so you get the average of two rows?
Member
Posts: 724
Joined: Apr 12 2015
Gold: 7,772.91
Mar 11 2016 07:06pm
Quote (carteblanche @ Mar 10 2016 01:26pm)
If you're using avg,I assume you wanted to union the max and min so you get the average of two rows?


This

select avg(lat) `Average lat` from (select max(lat) `lat` from zips where state_prefix like 'MO' UNION select min(lat) `lat` from zips where state_prefix like 'MO');
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll