Home  >  Q&A  >  body text

mysql报错 unknown column 'a.plat' in ON clause

select truncate(a.lat, 2) as plat, truncate(a.lng, 2) as plng, temp.latt, temp.lngt from user_post as a inner join 
(select truncate(user_post.lat, 2) as latt, truncate(user_post.lng, 2) as lngt from user_post group by latt, lngt having count(latt) >= 4 and count(lngt)>= 4) as temp 
on (a.plat = temp.latt and a.plng = temp.lngt);

Why is an error like unknown column 'a.plat' in ON clause reported?

漂亮男人漂亮男人2668 days ago1004

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-06-30 09:56:48

    aThe alias points to the table user_post. Judging from your statement, the user_post table has a lat field but no plat field.
    So a.plat in the on condition is wrong.

    Try adding brackets:

    select a.plat, a.plng, temp.latt, temp.lngt 
    
    from 
    
    (select truncate(lat, 2) as plat, truncate(lng, 2) as plng from user_post) as a 
    
    inner join 
    
    (select truncate(lat, 2) as latt, truncate(lng, 2) as lngt from user_post group by latt, lngt having count(latt) >= 4 and count(lngt)>= 4) as temp 
    
    on a.plat = temp.latt and a.plng = temp.lngt;
    

    reply
    0
  • Cancelreply