首页 \ 问答 \ MySQL将值赋给一个空别名(MySQL assigning value to a null alias)

MySQL将值赋给一个空别名(MySQL assigning value to a null alias)

结果表格:

result_event | name          |  position
-------------+---------------+------------
1            | Jason Smith   |  1
1            | David Johnson |  2
1            | Randy White   |  3
1            | Billy Hansen  |  4 
2            | Wally Mann    |  1
2            | Jason Smith   |  2
2            | Billy Hansen  |  3
2            | David Johnson |  4
2            | Randy White   |  5

我有一张比赛结果如上表。 我想通过他们在两场比赛中的组合位置来排序车手。 (例如1号加2号= 3号,2号加4号= 6号等)。赛车手“Wally Mann”没有参加第一场比赛,即使他赢得了第二场比赛,他也应该在所有其他比赛中进球。

预期结果:

Name          | Race1  | Race2
--------------+--------+-------
Jason Smith   |   1    |   2
David Johnson |   2    |   4
Billy Hansen  |   4    |   3 
Randy White   |   3    |   5
Wally Mann    |   NULL |   1

当前查询:

SELECT name,
     CASE(WHEN result_event=1 then position else 0 END) Race1,
     CASE(WHEN result_event=2 then position else 0 END) Race2,
     SUM(position) eventscore
FROM results
GROUP BY name
ORDER BY eventscore DESC

在我当前的查询中,“Wally Mann”是第一个列表,因为(Null + 1)<(1 + 2)。 我能做些什么来使所有有两个结果的参赛者进入(Null + 1)结果?


results table:

result_event | name          |  position
-------------+---------------+------------
1            | Jason Smith   |  1
1            | David Johnson |  2
1            | Randy White   |  3
1            | Billy Hansen  |  4 
2            | Wally Mann    |  1
2            | Jason Smith   |  2
2            | Billy Hansen  |  3
2            | David Johnson |  4
2            | Randy White   |  5

I have a table with race results as above. I want to sort the riders by their combined placement in the two races. (eg 1st plus 2nd = 3, 2nd plus 4th = 6, etc.) Racer "Wally Mann" did not race the first race so even though he won the second race, he should be scored behind all others.

Desired Result:

Name          | Race1  | Race2
--------------+--------+-------
Jason Smith   |   1    |   2
David Johnson |   2    |   4
Billy Hansen  |   4    |   3 
Randy White   |   3    |   5
Wally Mann    |   NULL |   1

Current query:

SELECT name,
     CASE(WHEN result_event=1 then position else 0 END) Race1,
     CASE(WHEN result_event=2 then position else 0 END) Race2,
     SUM(position) eventscore
FROM results
GROUP BY name
ORDER BY eventscore DESC

In my current query, "Wally Mann" is first in the list because (Null + 1) < (1+2). What can I do to make the (Null + 1) result sort AFTER all the racers who have two results?


原文:https://stackoverflow.com/questions/50494618
更新时间:2023-02-07 17:02

最满意答案

否 - 如果您想使用AJAX进行深度链接,则必须使其以这种方式工作。 锚点是URL的唯一部分,可以在没有页面重新加载的情况下进行更新。 它通常不会发送到服务器,因此它总是由浏览器处理。

你可以做的一件事是在标签中有实际的链接,然后使用jQuery来更新链接:

<a href="page1.html" class="ajaxLoad">Page 1</a>

<script>
$(function(){
  $("a.ajaxLoad").each(function(){ this.href = '#' + this.href })
});
</script>

关闭JavaScript后,当用户点击链接时,会将用户重定向到“page1.html”。 否则,该链接将更改为锚链接,并且您应该能够使用深层链接代码进行拾取。 像这样的好处是,非JavaScript浏览器将能够正确使用链接(这包括搜索引擎蜘蛛)。


编辑:只要你知道,你可以做一些事情,而不是使用JavaScript来改变它。 例如,您可以附加到链接的点击处理程序,并使用load或其他方式更改要加载页面的区域。

$("a.ajaxLoad").click(function(e){
    e.preventDefault();
    $("#content").load(this.href + ' #content');
});

No - if you want to deep link using AJAX, you're going to have to make it work this way. The anchor is the only part of the URL that can be updated without the page reloading. It isn't generally sent to the server either so it's always handled by the browser.

One thing you could do is have the actual link in the a tag, then use jQuery to update the link:

<a href="page1.html" class="ajaxLoad">Page 1</a>

<script>
$(function(){
  $("a.ajaxLoad").each(function(){ this.href = '#' + this.href })
});
</script>

With JavaScript turned off, this will redirect the user to 'page1.html' when they click the link. Otherwise, the link is changed to an anchor one and you should be able to pick it up with your deep linking code. The benefit of something like this is that non-JavaScript browsers will be able to use the links correctly (and this includes search engine spiders).


Edit: Just so you know, there's a few things you can do rather than use JavaScript to change it. For example, you could attach to the click handler of the links and use load or something to change the area you want to load your page.

$("a.ajaxLoad").click(function(e){
    e.preventDefault();
    $("#content").load(this.href + ' #content');
});

相关问答

更多
  • 我们也试图自己做这件事,我会尽力打破这里的不同步骤。 回到你的例子,你记住设备标识和所有相关数据“id = userA”是正确的。 对于“iOS的沙盒本质”,我认为这意味着网页不允许在浏览器应用程序(Safari)之外存储信息,而应用程序(您的应用程序)无法访问其他应用程序存储的信息苹果浏览器)。 我们的解决方案是将此设备存储到浏览器以及您的应用(即后端服务器)均可访问的环境中的数据键值对。 下一个挑战仍然是最大的挑战,那就是如何从浏览器收集的信息中唯一识别这个设备? 与原生应用程序不同,浏览器中的Java ...
  • 通过使用target =“_ self”解决动态生成的链接以触发路由,由于某种原因角度抑制了链接。 solved by using target="_self" for the dynamically generated links to trigger routing, for some reason the angular suppresses the links.
  • Android深层链接机制不提供从Android深层链接机制明确排除某些URL的方法:您可以使用android:path明确包含路径,包含与android:pathPrefix匹配的前缀或匹配android:pathPrefix的通配符的android:pathPattern 。您可以使用*或.* 。 在你的情况下,你将不得不使用"/"并且使用你的应用(包括你的主页)打开你的网站的每个链接,或者让每个深层链接共享一个共同的前缀。 您还可以查看airbnb的DeepLinkDispatch库,这似乎允许排除特 ...
  • 对于这个https://github.com/defunkt/jquery-pjax,PJAX (推送状态ajax)可能是你最好的选择。 在使用推送状态API允许它使用真实的URL,如果浏览器不支持推送状态API,那么它简单地回退到让链接正常工作(而不是通过AJAX加载页面部分)。 如果你不是一个JQuery用户并且仍然喜欢PJAX的想法,那么还有一个替代的独立实现(因为我编写它而无耻地插入)你可以访问https://github.com/thybag/PJAX-Standalone PJAX (push- ...
  • 正如您注意到的那样,您需要设置$.mobile.pushStateEnabled = false ,但是能够取代JQM的内置导航支持还有很多。 我已经创建了一个完整的示例来启用PathJS支持http://jsfiddle.net/kiliman/4dkP8/和这里的实时版本http://systemex.net/jqm/pathjs/,以便您可以看到这些URL的样子。 你甚至可以预订标记一个哈希链接,它会导航到正确的页面。 首先,您需要禁用JQM的默认散列支持 $(document).bind('mobi ...
  • 否 - 如果您想使用AJAX进行深度链接,则必须使其以这种方式工作。 锚点是URL的唯一部分,可以在没有页面重新加载的情况下进行更新。 它通常不会发送到服务器,因此它总是由浏览器处理。 你可以做的一件事是在标签中有实际的链接,然后使用jQuery来更新链接: Page 1