English 中文(简体)
MySQL: 单列SUM (IF(cond,a,b)) v-column Sum()
原标题:MySQL: single column SUM(IF(cond,a,b)) vs muti-column Sum()

在转换为联合考试委员会的过程中,有I m的遗产LAMP应用。

问题涉及一个与“250K”记录相加的图表。 目前,“核心类型”一栏是一个连续体,1 = 目标,2 = 援助1,3 = 援助2。

为了达到每个参与者的目标/目标/目标/目标/目标2,询问会发现:

SUM(IF(scoreType=1,1,0)) AS goals, SUM(IF(scoreType=2,1,IF(scoreType=3,1,0))) AS assists

工作做得够好,但我很想知道,在总计划设计方面,如果问询环境会带来特别大集团、COUNT等。

In separate columns the query then becomes:

SUM(goal) AS goal, SUM(assist1) AS assist1, SUM(assist2) AS assist2

这是一种性能赢利(如果(cond,a,b)对等),其成本是略微增加的储存(3栏)。 页: 1

At the application layer one potential big win is moving from ORM non-supported SUM(if()) to column.Sum(); otherwise, I ll need to keep non-statically typed string SQL queries with the all-in-one-column approach

想法? 如何对待、请假或将非行和适用守则移至三栏办法?

Thanks for feedback!

最佳回答
SELECT scoreType, COUNT(scoreType)
FROM ...
GROUP BY scoreType

难道没有吗?


a. 比较替代品的诚实时机,使用更精确的平均数;

SELECT COUNT(CASE WHEN scoreType = 1 THEN id ELSE NULL END) AS goals,
       ...
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签