- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个表,需要按产品的季度创建总销售额,其中 account_name 和 deal_id = X。
然后,我想要一份上一季度涨幅最大的 10 名企业的名单。
我一直通过创建一个临时表来做到这一点,但该表的大小约为1G,性能达不到我们想要的水平。我们可以创建另一个汇总表,但在这样做之前,我想看看是否有人对首先使用该表有建议。
account_name product_title type period deal_id total_amount
Account1 product1 Type A 2002_Q4 9100 146.54
Account1 product1 Type B 2002_Q4 9100 34.32
Account1 product1 Type C 2002_Q4 9100 0.02
Account1 product2 Type A 2002_Q4 9100 14.45
Account1 product2 Type B 2002_Q4 9100 3.58
Account1 product1 Type A 2002_Q3 9100 68.23
Account1 product1 Type B 2002_Q3 9100 12.56
Account1 product1 Type C 2002_Q3 9100 75.21
Account1 product2 Type A 2002_Q3 9100 5.68
Account1 product2 Type B 2002_Q3 9100 3.2
product1 180.88 2002_Q4 16%
product2 18.03 2002_Q4 103%
product1 156 2002_Q3
product2 8.88 2002_Q3
好的,我添加了新数据,并包括了与上一季度相比增长情况的结果。
最佳答案
这是使用固定四分位数的一种方法:
select d.product_title, ((
select sum(d1.total_amount)
from deals d1
where d1.account_name = 'Account1'
and d1.deal_id = d.deal_id
and d1.product_title = d.product_title
and d1.period = '2002_Q4'
) - sum(d.total_amount)) / sum(d.total_amount) * 100
as diff
from deals d
where d.account_name = 'Account1'
and d.deal_id = 9100
and d.period = '2002_Q3'
group by d.product_title
order by diff desc
limit 10
http://sqlfiddle.com/#!9/65bd95/26
这是另一个 - 连接两个子查询:
select
q3.product_title,
100 * (q4.total - q3.total) / q3.total as diff
from (
select d.product_title, sum(d.total_amount) as total
from deals d
where d.account_name = 'Account1'
and d.deal_id = 9100
and d.period = '2002_Q3'
group by d.product_title
) q3
join (
select d.product_title, sum(d.total_amount) as total
from deals d
where d.account_name = 'Account1'
and d.deal_id = 9100
and d.period = '2002_Q4'
group by d.product_title
) q4 using (product_title)
order by diff desc
limit 10
http://sqlfiddle.com/#!9/65bd95/9
一个有用的索引是(account_name,period,deal_id,product_title,total_amount)
。前三列可以按任何顺序排列。最后一个是可选的,但使其成为“覆盖”索引。
关于mysql - SQL 季度总计和增长百分比前十名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45491265/
增长,则让
当我输入内容时,如何移动 p 段落下方的所有元素,即 contenteditable。 这是我的代码: body, html { margin: 0; padding: 0; backgr
我要解决的问题: 我有一个包含 div 的外部 div。 content 内部和外部 div 之间的边距应始终相同。 当内部 div 增长/收缩时,外部 div
这document Ulrich Drepper 称为“图书馆设计、实现和维护的良好实践”(第 5 页底部): [...] the type definition should always crea
有什么方法可以获取 QPainterPath 并将其展开,就像 Photoshop 中的“选择”>“增长...”(或“展开...”)命令一样? 我想获取从 QGraphicsItem::shape 返
假设,为了问题的目的,我们有一个内存池,最初分配了 n 个 block 。但是,当达到容量时,池想要增长并变成原来大小的两倍 (2n)。 现在可以使用 C 中的 realloc 完成此调整大小操作,但
假设,为了问题的目的,我们有一个内存池,最初分配了 n 个 block 。但是,当达到容量时,池想要增长并变成原来大小的两倍 (2n)。 现在可以使用 C 中的 realloc 完成此调整大小操作,但
我正在研究 boost 库的共享内存部分,为更大的项目做准备。我需要一个共享内存段,在初始化时我不一定知道它的大小,所以我的计划是增加这个段。 我的初始实现有一个存储在共享内存中的 boost::in
这个问题在这里已经有了答案: How to disable equal height columns in Flexbox? (4 个答案) What are the differences bet
我有一个包含子表的表。我不希望子表影响表格的宽度——在溢出的情况下,我希望两者独立滚动。此外,由于子表是基于切换显示的,所以我不希望主表行根据子表是否可见而跳转 Here's代码笔。 我想我可以用 t
我有一个带栏的页面设计,它可以有一个、两个或三个栏。这些列的大小应相同。 为此我使用了 flexbox,它很好,允许我添加/删除我的列并让浏览器处理列宽的大小调整。 现在,当列中的文本大于列的宽度时,
要求: 我需要根据数据增长一个任意大的数组。 我可以猜测大小(大约 100-200),但不能保证数组每次都能适合 一旦它增长到最终大小,我需要对其执行数值计算,因此我更愿意最终得到一个二维 numpy
我有一个 3x256 规则的规则集。每个规则映射到一个 3x3 的值网格,这些值本身就是规则。 规则示例: 0 -> [[0,0,0],[0,1,0],[0,0,0]] 1 -> [[1,1,1],
我有 3 个 div,如果我给前两个 div flex: 0.5,如果我给了 flex-wrap: wrap,最后一个 div 应该移动到下一行>。如果我错了,请指正。 以下是我的 html/css:
在文档和 Bootstrap v4 问题中 (here) ,我看不到任何支持 flex-grow 的计划,例如语法如下: I use all the space lef
要求: 我需要从数据中增加一个任意大的数组。 我可以猜测大小(大约 100-200),但不能保证每次都适合数组 一旦它增长到最终大小,我需要对其执行数值计算,因此我希望最终得到一个二维 numpy 数
我知道(并在互联网上阅读-包括此资源)。增加内存的逻辑是:如果len数组小于1024-golang将array乘以2,否则将len乘以1.25(并且我们在源代码中看到了这个问题https://gith
当输入长文本时,WPF TextBox 控件会增长。 这个问题已经在 Stackoverflow 中提出了 我也引用了一些答案,但我仍然没有找到有效的正确答案。 Here提到了同样的问题,但没有针对此
我在使用 Vaadin HorizonalLayout 时遇到问题 - 我希望左侧组件填充大部分水平空间,如 Fiddle 所示 但是,当我运行 Vaadin 应用程序时,这两个组件会平分屏幕。
关于这个fiddle , 当我点击 a href在这种情况下这是一个图像,我希望图像从 div 开始增长/过渡以通过过渡/缩放填充整个页面它被放置在其中。如果这不可能,我想用 div 的背景颜色填充页
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 6 年前。 Improve this q
我是一名优秀的程序员,十分优秀!