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
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
最满意答案
最后我用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 Mapping lost local code)[2023-10-31]
不幸的是,由于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 ...
-
使用挖空映射将硬编码数据映射到服务器端生成的数据(Mapping hard coded data with server side generated data using knockout mapping)[2023-07-16]
通过使用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线程参数不是我的问题,但对于其他人来说,确保您在正确的线程上处理事件可能很重要 ... -
使用Knockout映射插件正确映射数组元素(Correctly mapping array element using the Knockout mapping plugin)[2022-01-28]
我最终使用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 ...