- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个表,存储 5 个不同的网格坐标,我需要按距给定坐标的最短距离列出这些坐标。所以我想我会使用联合并查询表 5 次,每次使用不同列的别名。但似乎每个别名都返回第一个选择的值。这是我尝试过的查询。
SELECT floor(sqrt(pow((cord_1x-$cord1x),2)+pow((cord_1y-$cord1y),2))) as distance,
alliance_name, player_name, level, priority,cord_1x AS cordx, cord_1y AS cordy,
cord_2x, cord_2y, cord_3x, cord_3y, cord_4x, cord_4y, cord_5x, cord_5y
FROM cords
where alliance_id = " .$myalliance_id. " AND cord_1x <> '' AND active ='1'
UNION
SELECT floor(sqrt(pow((cord_2x-$cord1x),2)+pow((cord_2y-$cord1y),2))) as distance,
alliance_name, player_name, level, priority,cord_1x, cord_1y,
cord_2x AS cordx, cord_2y AS cordy, cord_3x, cord_3y, cord_4x, cord_4y, cord_5x, cord_5y
FROM cords
where alliance_id = " .$myalliance_id. " AND cord_2x <> '' and active ='1'
order by distance ASC";
我想要得到的结果是
玩家名称联盟名称等级优先距离线
乔恩坏人 10 高 4 1,1
乔恩坏人 10 高 6 2,2
我得到的是
玩家名称联盟名称等级优先距离线
乔恩坏人 10 高 4 1,1
乔恩坏人 10 高 6 1,1
看起来我使用的别名不正确。它不会将下一列的值应用于第一个选择中使用的相同别名。
请记住,我只使用了 2 个选择来进行测试,这更容易,但是当我弄清楚这一点时,我将查询表 5 次
最佳答案
首先,使用UNION ALL
。您不希望 UNION
决定合并两个结果集行,因为它们是相同的。
其次,对于 UNION ALL
操作中的两个子查询,您应该按名称、数据类型和位置来调整列。您试图仅通过名称和数据类型来使它们一致。
也就是说,你需要这样的东西:
SELECT floor(sqrt(pow((cord_1x-$cord1x),2)+pow((cord_1y-$cord1y),2))) as distance,
alliance_name, player_name, level, priority,
cord_1x AS cordx, cord_1y AS cordy, /*alias columns */
cord_1x, cord_1y, cord_2x, cord_2y, /* cord_1 columns repeat */
cord_3x, cord_3y, cord_4x, cord_4y, cord_5x, cord_5y
FROM cords
where alliance_id = " .$myalliance_id. " AND cord_1x <> '' AND active ='1'
UNION ALL
SELECT floor(sqrt(pow((cord_2x-$cord1x),2)+pow((cord_2y-$cord1y),2))) as distance,
alliance_name, player_name, level, priority,
cord_2x AS cordx, cord_2y AS cordy, /* different alias columns */
cord_1x, cord_1y, cord_2x, cord_2y, /* cord_2 columns repeat */
cord_3x, cord_3y, cord_4x, cord_4y, cord_5x, cord_5y
FROM cords
where alliance_id = " .$myalliance_id. " AND cord_2x <> '' and active ='1'
order by distance ASC";
关于php - mysql php使用相同的别名查询同一个表5次,但每次使用该别名用于不同的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24470687/
上下文:我已经在域根上设置了一个用于 GIS 测试和 dokuwiki 的虚拟机服务器。我想在子域上提供 gis Web 应用程序,这样 dokuwiki url 重命名就不会发生冲突(而且感觉更干净
这个问题在这里已经有了答案: If two variables point to the same object, why doesn't reassigning one variable affe
代码如下: Select Branch.BranchName, Sum(Inventory.OnHand) From Inventory, Branch Inventory.BranchNum = B
我的目标是创建一种“Javascript 库”,如果您可以这样调用它的话。我打算在浏览网页时使用它来操作页面,将其作为 greasemonkey 脚本动态加载。这个想法是将“win”映射到window
是否可以在 javascript 中以某种方式为本地变量分配别名/引用? 我的意思是类似 C 的东西: function foo() { var x = 1; var y = &x; y+
SQLite 别名 您可以暂时把表或列重命名为另一个名字,这被称为别名。使用表别名是指在一个特定的 SQLite 语句中重命名表。重命名是临时的改变,在数据库中实际的表的名称不会改变。 列别名用来
我有以下导入(在同一个 TS 源文件中): import {Vector as sourceVector} from "ol/source"; import {Vector} from "ol/lay
我想弄清楚 this 到底是什么行是在这个 github json 项目的 cmake 文件中, add_library(${NLOHMANN_JSON_TARGET_NAME} INTERFACE)
使用集合时如何创建别名 (AS)。 $collection->addAttributeToSelect('total_qty') 可以这样做: $collection->getSelect()->co
这个问题在这里已经有了答案: Pass an argument to a Git alias command (4 个回答) 去年关闭。 我的团队在不同的分支上工作,通常,我需要快速从分支切换来帮助他
我正在寻找一种向我的 vimrc 添加自定义命令或别名的方法,以便快速切换到 Vim 中的不同目录。我曾经设置过一些东西,但丢失了那个配置。这是用于 Linux 设置。 基本上,我想设置一个别名(如果
我使用 Delphi 和 Firebird 1.5 开发了一个应用程序,其中服务器与应用程序位于同一台计算机上。我现在正在将应用程序部署到另一个站点,其中 Firebird 服务器( super 服务
我创建了一个全新的 React 应用 create-react-app demo 我需要为某些目录/组件创建别名,例如: import { Header } from '@uicomponents'
我正在尝试打印有向图,并且不断更改各种节点属性,例如颜色和形状。有什么方法可以使用一次定义并用于多个节点的变量?理想情况下,我想要这样的东西: digraph g { building_color =
server { listen 80; server_name pwta; root html; location /test/{ alia
我想匹配多个数组,并在匹配时构建另一个数组。该键可以在任意数量的数组中匹配,也可以根本不匹配。 [ [{ 'a': 13 }, { 'b': 62 }, { 'c': 93 }, { 'd': 52
经过审查后,我需要更改一些代码并将所有更改代码重新推送到远程分支上。 所以我想使用别名(例如:git repushall)在 git 上自动化这些不同的命令: git add . git commit
我有一个这样的查询: select a1.name, b1.info from (select name, id, status from table1 a) as a1 righ
我想给一些 racket 2htdp 函数/宏起别名,这样我就可以为我的 child 将它们翻译成另一种语言。 我可以简单地用define给函数起别名。我在使用 big-bang 结构时遇到了麻烦;例
经过审查后,我需要更改一些代码并将所有更改代码重新推送到远程分支上。 所以我想使用别名(例如:git repushall)在 git 上自动化这些不同的命令: git add . git commit
我是一名优秀的程序员,十分优秀!