我已经设法一起破解SQL查询,直到我意识到数据库中的某些成员由于我们使用的插件删除了非ascii名称而具有空名称。我在我的页面上显示这些统计数据,并且没有名字的人不能很好地工作。我知道在使用WHERE子句时如何不显示NULL但我不太确定何时没有使用WHERE子句。
到目前为止我所拥有的 -
SELECT player_stats.player_name, COUNT(player_kill.killer)
FROM player_stats
LEFT JOIN player_kill ON player_stats.player_id = player_kill.killer
GROUP BY player_stats.player_name
HAVING COUNT(player_kill.killer) > 1
ORDER BY COUNT(player_kill.killer) DESC;
答案 0 :(得分:0)
JOIN
子句介于所有GROUP BY
子句和WHERE player_name IS NOT NULL
之间。如果NULL
不起作用,则名称可能是空字符串,而不是SELECT s.player_name, COUNT(*) AS count
FROM player_stats AS s
INNER JOIN player_kill AS k ON s.player_id = k.killer
WHERE s.player_name IS NOT NULL AND s.player_name != ''
GROUP BY s.player_name
ORDER BY count DESC;
,因此您还需要检查它。
INNER JOIN
此外,如果您不想获得0计数,请使用LEFT JOIN
而不是<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="newfeed_v2"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<payloadFactory media-type="json">
<format>[
{"id": "1",
"type": "object",
"name": "first",
"bounds":"[[-0.256,51.531],[-0.102,51.656]]",
"displayName": "first record"},
{"id": "2",
"type": "object",
"name": "second",
"bounds":"[[-0.256,51.531],[-0.102,51.656]]",
"displayName": "second record"},
{"id": "4",
"type": "object",
"name": "tercero",
"bounds":"[[-0.256,51.531],[-0.102,51.656]]",
"displayName": "tercer record"}
]
</format>
<args/>
</payloadFactory>
<log level="full"/>
<loopback/>
</inSequence>
<outSequence>
<log level="full">
<property name="MESSAGE" value="FIRST"/>
</log>
<property name="Person" scope="default">
<value xmlns=""/>
</property>
<foreach id="foreach_1" expression="//jsonArray/jsonElement">
<sequence>
<payloadFactory media-type="json">
<format>{
"name" : "$1",
"bounds" : "$2"
}
</format>
<args>
<arg evaluator="json" expression="$.displayName"/>
<arg evaluator="json" expression="$.bounds"/>
</args>
</payloadFactory>
<enrich>
<source clone="true" xpath="$body//jsonObject"/>
<target action="child" xpath="$ctx:Person"/>
</enrich>
<log level="full">
<property name="MESSAGE1" value="ENDLOOP"/>
</log>
</sequence>
</foreach>
<enrich>
<source clone="true" xpath="$ctx:Person"/>
<target type="body"/>
</enrich>
<log level="full">
<property name="MESSAGE" value="ENDLOOP"/>
</log>
<!--property name="messageType" value="text/xml" scope="axis2" type="STRING"/--><log level="full">
<property name="TRANSFORMED MESSAGE" value="LAST"/>
</log>
<send/>
</outSequence>
<faultSequence/>
</target>
<description/>
</proxy>
。
答案 1 :(得分:0)
如果您不想更改查询,可以通过检查是否为空来替换播放器名称。
SELECT ISNULL(s.player_name, "RandomPlayer"), COUNT(*) AS count
FROM player_stats AS s
INNER JOIN player_kill AS k ON s.player_id = k.killer
WHERE s.player_name IS NOT NULL AND s.player_name != ''
GROUP BY s.player_name
ORDER BY count DESC;