visual-foxpro - 根据另一个字段的最大值选择记录
问题描述
我正在尝试根据土地面积字段的最大值提取不同城市名称及其纬度和经度的列表。我得到的最好的结果是“SQL:关联字段错误”错误。
SELECT a.primary_city as city ;
, a.state as state_id ;
, SPACE(30) as state_name ;
, a.approximate_latitude as latitude ;
, a.approximate_longitude as longitude ;
FROM citystate a ;
WHERE a.area_land = ;
(SELECT MAX(VAL(b.area_land)) ;
FROM citystate b ;
WHERE (b.primary_city = a.primary_city ;
AND b.state = a.state)) ;
GROUP BY a.primary_city ;
, a.state ;
, a.approximate_latitude ;
, a.approximate_longitude
不确定这甚至会起作用,所以希望得到一些帮助。
谢谢。
解决方案
VFP 不支持此类 SQL。你可以这样写:
SELECT csa.primary_city as city ;
, csa.state as state_id ;
, SPACE(30) as state_name ;
, csa.approximate_latitude as latitude ;
, csa.approximate_longitude as longitude ;
FROM citystate csa ;
INNER JOIN ;
(SELECT primary_city, state, MAX(VAL(area_land)) as maxALand ;
FROM citystate ;
GROUP BY primary_city, state ) csb ;
ON csb.primary_city = csa.primary_city ;
AND csb.state = csa.state ;
WHERE VAL(csa.area_land) = csb.maxALand
推荐阅读
- github - 如何从 yocto 中的 github url 获取文件?
- flutter - 如何在颤动中隐藏溢出的内容?
- terraform - 如何自动激活 Synapse Workspace
- android-studio - Android Studio Emulator 无法在使用 WHPX 的 Windows 11 上运行
- flutter - Flutter intlphonefield 在键盘焦点上消失以按国家名称搜索
- javascript - 在 POST 方法 Sails.js 中实现 JSON 数组输入
- android - 如何在通信应用程序中显示推送通知到达时的呼叫屏幕(Flutter android)
- python - 在多索引数据框中添加新行作为标题
- node.js - 为什么运行两个不同路径的 websocket 服务器会导致客户端得到“无效的帧头”并断开连接?
- angular - 如何更新 Angular 库项目?