首页 \ 问答 \ SUM(some_column)WHERE some_column匹配(SUM (some_column) WHERE some_column matches)

SUM(some_column)WHERE some_column匹配(SUM (some_column) WHERE some_column matches)

所以我有一个表,我正在尝试获取SUM(activity_weight)WHERE activity_typeid是唯一的。

每场比赛都有无限量的activity_typeid。

正如您在下面的代码中看到的,我想知道是否有一些SQL函数可以找到某些内容的SUM,例如id是唯一的?

感谢任何提前帮助!

我在下面附上了我的桌子和所需输出的照片

在此处输入图像描述

 SELECT a.userid, u.name, u.profilePic , 
  SUM(activity_weight) AS totalPoints , 

  //sum the points when the activity_typeid is unique and make an extra column for each of those sums
  SUM(CASE WHEN activity_typeid //is unique// THEN activity_weight    ELSE NULL END) AS specific_points , 

  FROM activity_entries a INNER JOIN users1 u ON u.id = a.userid 

  WHERE competitionId = '$competitionId' GROUP BY a.userid ORDER BY totalPoints

So I have a table, and I'm trying to get the SUM(activity_weight) WHERE activity_typeid is unique.

Each competition has an unlimited amount of activity_typeid's.

As you can see in my code below, I wonder if there is some SQL function to find the SUM of something WHERE the id is unique for example?

THANKS FOR ANY HELP IN ADVANCE!

I've attached a photo of my table and desired output below

enter image description here

 SELECT a.userid, u.name, u.profilePic , 
  SUM(activity_weight) AS totalPoints , 

  //sum the points when the activity_typeid is unique and make an extra column for each of those sums
  SUM(CASE WHEN activity_typeid //is unique// THEN activity_weight    ELSE NULL END) AS specific_points , 

  FROM activity_entries a INNER JOIN users1 u ON u.id = a.userid 

  WHERE competitionId = '$competitionId' GROUP BY a.userid ORDER BY totalPoints

原文:https://stackoverflow.com/questions/18362322
更新时间:2023-04-11 22:04

最满意答案

最后我用knockout.reactor插件解决了我自己的问题,如果我们删除所有辅助结构,它将如下所示:

var ViewModel = ko.mapping.fromJS(test_data);

ko.applyBindings(ViewModel);

ko.watch(ViewModel, { depth: -1 }, function(parents, child, item) {
    // here we need to filter watches and update only when needed, see jsfiddle
    ko.mapping.fromJS(test_data2, {}, ViewModel);
});

这样我们更新选择并且没有订阅递归的麻烦。

完整版(详见控制台输出): http//jsfiddle.net/r7Lo7502/


At last I've solved my own question with knockout.reactor plugin, If we remove all auxiliary constructions, it will look like:

var ViewModel = ko.mapping.fromJS(test_data);

ko.applyBindings(ViewModel);

ko.watch(ViewModel, { depth: -1 }, function(parents, child, item) {
    // here we need to filter watches and update only when needed, see jsfiddle
    ko.mapping.fromJS(test_data2, {}, ViewModel);
});

This way we update selects and don't have troubles with subscription recursions.

full version (see console output for details): http://jsfiddle.net/r7Lo7502/

相关问答

更多
  • 每次单击该选项卡时,都会触发自定义控件的加载事件。 我想可能会有问题。 The loaded event of your custom control fires every time you click on that tab. I think there could be the problem.
  • 问题是当你应该检查vm是否被定义时,你是在写你现有的vm,如果是这样的话 KnockoutJS并将单个对象绑定到viewmodel var viewModel; function displayArguments(data){ var page=document.getElementById('Results'); page.style.visibility='visible'; if(!!viewModel){ viewModel.prop1(data.prop1) ...
  • 不幸的是,由于TFS覆盖了本地文件,您已经丢失了更改。 您在进行更改后设置工作区,以便TFS对它们一无所知以进行合并。 如果您创建了任何不受源代码控制的其他文件,那么它们应该仍然存在于本地,所以也许您没有丢失所有内容 将来,如果先设置工作区,那么显然可以对文件进行更改,TFS会知道它。 或者,将工作区映射到其他本地文件夹,然后复制更改。 如果您使用的是本地工作区,则TFS将为您生成挂起的更改。 Unfortunately you've lost the changes as TFS has overwrit ...
  • 一种选择是通过已应用ACL的公共端点进行通信,以仅允许来自特定IP地址的传入流量(在您的情况下,您只允许来自sub1部署的与xyz.cloudapp.net关联的公共VIP的xyz.cloudapp.net )。 这允许在不处理vnet或vpn的情况下进行通信。 如果您的应用涉及消息传递(通过服务总线或Azure队列),则订阅边界无关紧要。 同一地区内的服务不收取带宽费用。 One option is to communicate via public endpoints that have ACL's a ...
  • 最后我用knockout.reactor插件解决了我自己的问题,如果我们删除所有辅助结构,它将如下所示: var ViewModel = ko.mapping.fromJS(test_data); ko.applyBindings(ViewModel); ko.watch(ViewModel, { depth: -1 }, function(parents, child, item) { // here we need to filter watches and update only when ...
  • 通过使用arraymap解决它.. this.tables = ko.observableArray(); var temptables= ko.utils.arrayMap(dataFromServer, function(item) { return new Table(item.id,item.name, item.students, item.maxstudents, item.allowedstudentgender); }); this.table ...
  • 如果订阅是自动更新的,则事务将不会传递paymentQueue:updateTransactions方法。 更新只发生在商店。 如果你想测试它,你必须: 如果您将收据存储在应用程序服务器上,请重新验证收据。 在您的iOS客户端上重新验证收据 (http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/VerifyingStoreReceipts/VerifyingStor ...
  • 映射插件正如您所期望的那样工作。 您的问题很简单,您希望插件在对象的每个级别创建可观察对象。 这不是插件的工作方式。 它只会为“叶子”属性创建可观察对象。 所以在你的情况下, $root.Results.highlighting不是作为一个observable创建的。 然而,docs上的id属性被创建为observables,因此解决方案是。 $root.Results.highlighting[Id()] 我相信你可能会感到困惑,因为你的一个小提琴正在分配自我。结果两次,这使得它似乎以一种方式工作,而事 ...
  • 原来是垃圾收集器删除了订阅。 我将不得不阅读内部,但当我更换 this.mEventAggregator.GetEvent().Subscribe(SomeFunction); 同 this.mEventAggregator.GetEvent().Subscribe( SomeFunction, ThreadOption.UIThread, true); 它开始工作了。 UI线程参数不是我的问题,但对于其他人来说,确保您在正确的线程上处理事件可能很重要 ...
  • 我最终使用ko.toJS而不是ko.mapping.toJS 。 ko.toJS不关心__ko_mapping__ ,并映射所有内容(包括__ko_mapping__ )。 这意味着它的映射比我需要的多一点,但除此之外它工作得很好。 I ended up using ko.toJS instead of ko.mapping.toJS. ko.toJS does not care about __ko_mapping__, and maps everything (including __ko_mappin ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。