我正在为高速公路车队制作一个排名表,我有一个查询,根据车队结果计算所需数据。我正在努力解决的问题是分数差异(得分和对手得分之间的差异)。
SELECT tbl_clubs.club, tbl_clubs.club_id,
SUM(if(tbl_clubs.club_id = tbl_fixtures.away AND tbl_fixtures.awayscore is not null ,1,0)) +
SUM(if(tbl_clubs.club_id = tbl_fixtures.home AND tbl_fixtures.homescore is not null,1,0 )) as `M`,
SUM( if( tbl_clubs.club_id = tbl_fixtures.home
AND tbl_fixtures.homescore > tbl_fixtures.awayscore, 1, 0 ) ) AS `W`,
SUM( IF( tbl_clubs.club_id = tbl_fixtures.home AND tbl_fixtures.awayscore = tbl_fixtures.homescore, 1, 0 ) ) AS `HD`,
SUM( if( tbl_clubs.club_id = tbl_fixtures.home
AND tbl_fixtures.homescore < tbl_fixtures.awayscore, 1, 0 ) ) AS `HL`,
SUM(if(tbl_clubs.club_id = tbl_fixtures.away
AND tbl_fixtures.awayscore > tbl_fixtures.homescore
AND tbl_fixtures.awayscore - tbl_fixtures.homescore >=7,1,0)) AS `4W`,
SUM(if(tbl_clubs.club_id = tbl_fixtures.away
AND tbl_fixtures.awayscore > tbl_fixtures.homescore
AND tbl_fixtures.awayscore - tbl_fixtures.homescore <=6,1,0)) AS `3W`,
SUM( IF( tbl_clubs.club_id = tbl_fixtures.away AND tbl_fixtures.awayscore = tbl_fixtures.homescore, 1, 0 ) ) AS `AD`,
SUM(if(tbl_clubs.club_id = tbl_fixtures.away
AND tbl_fixtures.awayscore < tbl_fixtures.homescore
AND tbl_fixtures.homescore - tbl_fixtures.awayscore <=6,1,0)) AS `1L`,
SUM(if(tbl_clubs.club_id = tbl_fixtures.away
AND tbl_fixtures.awayscore < tbl_fixtures.homescore
AND tbl_fixtures.homescore - tbl_fixtures.awayscore >=7,1,0)) AS `L`,
@FOR:=SUM(IF(tbl_clubs.club_id = tbl_fixtures.away,tbl_fixtures.awayscore,0)) +
SUM(IF(tbl_clubs.club_id = tbl_fixtures.home,tbl_fixtures.homescore,0)) as `F`,
@Against:=SUM(IF(tbl_clubs.club_id = tbl_fixtures.home,tbl_fixtures.awayscore,0)) +
SUM(IF(tbl_clubs.club_id = tbl_fixtures.away,tbl_fixtures.homescore,0)) as `A`,
SUM(@For - @Against) as `PtsDiff`,
SUM( if( tbl_clubs.club_id = tbl_fixtures.home
AND tbl_fixtures.homescore > tbl_fixtures.awayscore, 3, 0 ) ) +
SUM( IF( tbl_clubs.club_id = tbl_fixtures.home AND tbl_fixtures.awayscore = tbl_fixtures.homescore, 1, 0 ) ) +
SUM(if(tbl_clubs.club_id = tbl_fixtures.away
AND tbl_fixtures.awayscore > tbl_fixtures.homescore
AND tbl_fixtures.awayscore - tbl_fixtures.homescore >=7,4,0)) +
SUM(if(tbl_clubs.club_id = tbl_fixtures.away
AND tbl_fixtures.awayscore > tbl_fixtures.homescore
AND tbl_fixtures.awayscore - tbl_fixtures.homescore <=6,3,0)) +
SUM( IF( tbl_clubs.club_id = tbl_fixtures.away AND tbl_fixtures.awayscore = tbl_fixtures.homescore, 2, 0 ) ) +
SUM(if(tbl_clubs.club_id = tbl_fixtures.away
AND tbl_fixtures.awayscore < tbl_fixtures.homescore
AND tbl_fixtures.homescore - tbl_fixtures.awayscore <=6,1,0)) as `Pts`
FROM tbl_clubs
INNER JOIN tbl_fixtures ON tbl_clubs.club_id = tbl_fixtures.home
OR tbl_clubs.club_id = tbl_fixtures.away
where tbl_clubs.league_id = 3
GROUP BY tbl_clubs.club_id
order by Pts desc, PtsDiff desc, club asc
所有查询都正常工作,除了
@FOR:=SUM(IF(tbl_clubs.club_id = tbl_fixtures.away,tbl_fixtures.awayscore,0)) +
SUM(IF(tbl_clubs.club_id = tbl_fixtures.home,tbl_fixtures.homescore,0)) as `F`,
@Against:=SUM(IF(tbl_clubs.club_id = tbl_fixtures.home,tbl_fixtures.awayscore,0)) +
SUM(IF(tbl_clubs.club_id = tbl_fixtures.away,tbl_fixtures.homescore,0)) as `A`,
SUM(@For - @Against) as `PtsDiff`,
我得到的结果是空的,我猜这很简单,任何帮助都会很好
首先,您需要确保null值始终默认为0而不是null。这是脚本中可能发生的事情,因此您应该确保0是唯一可行的默认值。这应该在执行此查询之前发生,尽管理想情况下是这样。根据您的脚本,情况似乎并非如此,因此您可能希望确保您已经设计了数据库来满足这一要求。
其次,查询中的变量分配并不像您希望的那样简单。您最好使用子查询进行初始化:
@FOR:=(select IFNULL(SUM(tbl_fixtures.awayscore),0) from tbl_fixtures where tbl_clubs.club_id = tbl_fixtures.away) +
(select IFNULL(SUM(tbl_fixtures.homescore),0) from tbl_fixtures where tbl_clubs.club_id = tbl_fixtures.home)
as `F`,
@Against:=(select IFNULL(SUM(tbl_fixtures.awayscore),0) from tbl_fixtures where tbl_clubs.club_id = tbl_fixtures.home) +
(select IFNULL(SUM(tbl_fixtures.homescore),0) from tbl_fixtures where tbl_clubs.club_id = tbl_fixtures.away)
as `A`,
SUM(@FOR - @Against) as `PtsDiff`,
不太优雅,但这应该行得通。请注意使用IFNULL来确保null转换为0。
问题内容: 我有一个学校的作业,任务之一是解释很多小的计算,并解释为什么Java给您输出它给您的输出。 计算之一是: 1 +‘2’+ 3 这对我来说是一个词汇错误,因为老师在我的系统上使用了错误的“撇号”,但是我与其他同学交谈,他们告诉我他们得到了实际的输出,因此我开始阅读并发现了认为它应该表示一个char变量,并且我也了解 了系统的特定类型,所以我更改了符号以使其适用于我的系统,现在我得到了答案
我在PHP中设置了这些变量: 然后,我想在另一个变量上使用上面的内容来计算,结果是: 分析错误:语法错误,意外的'$settings'(T_VARIABLE)' 如何使用这些变量创建计算?
假设我在pebble或freemarker中有一个模板(我正在考虑使用的两个引擎)。它可能看起来像这样: 在我的Java代码中,我需要提供一个包含这些变量的对象,我相信它可以是两个引擎中变量名到对象的映射。 编辑:我不知道模板会是什么样子,当我必须评估它,因为它将由用户定义。甚至他们提供的变量都将是用户定义的字符串-这就是为什么我需要在提供数据之前获取(并分析)它们。
基本值.yaml service-x-values.yaml 值文件的计算顺序为: null
如果使用的两个数字和运算符存储在变量中(用户输入),如何返回计算结果。 我正在创建一个简单的计算器,并试图输出“Number”“Operator”“Number2”的答案,根据用户输入的内容,答案可以是任何内容。 当输入这些数字和运算符时,输出返回“5 5=5 5”,我试图返回“5 5=10”。
客户端计算基于 Turf.js 分析接口实现。Turf.js 是一个用于空间分析的 JavaScript 库。它包括传统的空间操作,用于创建 GeoJSON 数据的帮助函数,以及数据分类和统计工具。Turf.js 可以作为客户端插件添加到您的网站,也可以使用 Node.js 运行 Turf 服务器。 Turf.js 使用 GeoJSON 来处理所有地理数据。Turf.js 的数据标准是 WGS84