- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有下表:
CREATE TABLE PaL (
Event_Date DATE,
Country CHAR(2),
Category CHAR(255),
Revenue INTEGER(255),
Costs INTEGER(255)
);
INSERT INTO PaL
(Event_Date, Country, Category, Revenue, Costs)
VALUES
("2017-01-31", "DE", "Apparel", "692.09816652375", "-173.071989376023"),
("2017-02-28", "DE", "Apparel", "8419.9977988914", "-7622.61265984317"),
("2017-03-31", "DE", "Apparel", "2018.80471444031", "-1498.76213884283"),
("2017-04-30", "DE", "Apparel", "8863.15663035884", "-7965.69268589649"),
("2017-05-31", "DE", "Apparel", "6838.4514829573", "-1088.70351845663"),
("2017-06-30", "DE", "Apparel", "2025.73421386331", "-483.454199185678"),
("2017-07-31", "DE", "Apparel", "5389.0163788639", "-2643.93624645182"),
("2017-08-31", "DE", "Apparel", "6238.85870250446", "-1985.9879371866"),
("2017-09-30", "DE", "Apparel", "2294.62451106469", "-1864.98271539745"),
("2017-10-31", "DE", "Apparel", "4141.2074159951", "-197.773961036073"),
("2017-11-30", "DE", "Apparel", "1456.17584217397", "-1018.54129047119"),
("2017-12-31", "DE", "Apparel", "3623.54984724091", "-745.715567286581"),
("2017-01-31", "DE", "Shoes", "5955.20947079185", "-4745.39564508682"),
("2017-02-28", "DE", "Shoes", "9555.29563511224", "-5729.82601329738"),
("2017-03-31", "DE", "Shoes", "5490.36170257556", "-925.286457266534"),
("2017-04-30", "DE", "Shoes", "7652.35548686073", "-7335.32532050594"),
("2017-05-31", "DE", "Shoes", "9102.38987703511", "-5724.92574170071"),
("2017-06-30", "DE", "Shoes", "1703.95901703023", "-1678.19547060803"),
("2017-07-31", "DE", "Shoes", "3679.60045104324", "-2095.94207835501"),
("2017-08-31", "DE", "Shoes", "6672.43210841331", "-3475.55411014914"),
("2017-09-30", "DE", "Shoes", "7718.7744220635", "-1252.75877307055"),
("2017-10-31", "DE", "Shoes", "6976.01564153854", "-509.991595559256"),
("2017-11-30", "DE", "Shoes", "4725.46976319905", "-2835.09460170927"),
("2017-12-31", "DE", "Shoes", "8390.84483147949", "-7476.83516162742"),
("2017-01-31", "US", "Apparel", "939788.159047677", "-742666.846083707"),
("2017-02-28", "US", "Apparel", "826418.514009279", "-702997.151099908"),
("2017-03-31", "US", "Apparel", "775940.69563018", "-211238.971709086"),
("2017-04-30", "US", "Apparel", "516829.583069596", "-407521.856789393"),
("2017-05-31", "US", "Apparel", "635701.377748304", "-627829.016481388"),
("2017-06-30", "US", "Apparel", "757852.95599751", "-740948.867522139"),
("2017-07-31", "US", "Apparel", "154224.257732688", "-139805.456987081"),
("2017-08-31", "US", "Apparel", "102035.465731255", "-100103.875992667"),
("2017-09-30", "US", "Apparel", "880671.692714021", "-665324.083753931"),
("2017-10-31", "US", "Apparel", "187868.653562564", "-105676.793254039"),
("2017-11-30", "US", "Apparel", "994600.486892401", "-177382.899789215"),
("2017-12-31", "US", "Apparel", "813824.90461202", "-132527.311010471"),
("2017-01-31", "US", "Shoes", "661069.933966637", "-454778.427240679"),
("2017-02-28", "US", "Shoes", "675942.334464692", "-254489.623313569"),
("2017-03-31", "US", "Shoes", "473604.307973888", "-404226.047653847"),
("2017-04-30", "US", "Shoes", "872018.822577053", "-348781.396359871"),
("2017-05-31", "US", "Shoes", "718012.023481434", "-625306.312927362"),
("2017-06-30", "US", "Shoes", "688487.679029354", "-584512.575888519"),
("2017-07-31", "US", "Shoes", "690085.013711018", "-581753.771085971"),
("2017-08-31", "US", "Shoes", "204473.88894161", "-172301.871771595"),
("2017-09-30", "US", "Shoes", "516932.092423463", "-328002.737710081"),
("2017-10-31", "US", "Shoes", "609355.245817292", "-323624.391366703"),
("2017-11-30", "US", "Shoes", "313599.625504231", "-210253.020497022"),
("2017-12-31", "US", "Shoes", "723573.681040319", "-107333.764977439"),
("2017-01-31", "NZ", "Apparel", "81292.9610624533", "-27354.678748396"),
("2017-02-28", "NZ", "Apparel", "77473.6231986387", "-47920.2900396812"),
("2017-03-31", "NZ", "Apparel", "93819.4377266116", "-47582.1878235771"),
("2017-04-30", "NZ", "Apparel", "25580.8516093492", "-21277.2651303701"),
("2017-05-31", "NZ", "Apparel", "82842.9415935231", "-30714.5952859941"),
("2017-06-30", "NZ", "Apparel", "50878.6190715448", "-33047.3841488076"),
("2017-07-31", "NZ", "Apparel", "61423.3558286064", "-10811.2817583225"),
("2017-08-31", "NZ", "Apparel", "77517.2989019148", "-56818.7461336424"),
("2017-09-30", "NZ", "Apparel", "74046.1258000888", "-10108.0702908427"),
("2017-10-31", "NZ", "Apparel", "79490.650598675", "-68562.5753547413"),
("2017-11-30", "NZ", "Apparel", "65000.3971251097", "-25174.1329786955"),
("2017-12-31", "NZ", "Apparel", "99152.6457285608", "-42855.8431883814"),
("2017-01-31", "NZ", "Shoes", "20703.8970205884", "-11911.9616025915"),
("2017-02-28", "NZ", "Shoes", "72841.2537140946", "-14166.6747335237"),
("2017-03-31", "NZ", "Shoes", "45391.6550622383", "-40325.1638601903"),
("2017-04-30", "NZ", "Shoes", "58074.2843201579", "-54483.1122507654"),
("2017-05-31", "NZ", "Shoes", "52127.2701338519", "-28026.7984458694"),
("2017-06-30", "NZ", "Shoes", "32900.9222204099", "-22780.2637095601"),
("2017-07-31", "NZ", "Shoes", "18809.3868235169", "-11500.4020522949"),
("2017-08-31", "NZ", "Shoes", "67001.2729206886", "-53280.8129552599"),
("2017-09-30", "NZ", "Shoes", "26889.4058005421", "-24218.8734875798"),
("2017-10-31", "NZ", "Shoes", "56330.7544011198", "-51382.4201254223"),
("2017-11-30", "NZ", "Shoes", "60954.7129549264", "-19834.7256352672"),
("2017-12-31", "NZ", "Shoes", "97527.2014993995", "-83137.4844853141");
然后我使用以下查询从表中获取数据:
Select Country, Category, sum(Revenue) as Revenue, sum(Costs) as Costs
FROM Pal
WHERE Event_Date BETWEEN "2017-01-01" AND "2017-01-31"
GROUP BY Country, Category WITH ROLLUP
您还可以在sql fiddle
here
中找到包含数据的表到目前为止,一切正常。
现在,我想知道如何避免 WITH ROLLUP
函数计算每个国家/地区下方列的总数。相反,它应该只计算列总计一次,所以最后的结果如下所示:
Country Category Revenue Costs
DE Apparel 692 -173
DE Shoes 5955 -4745
: : : :
: : : :
: : : :
US Shoes 661070 -454778
(null) (null) 1709502 -1241630
我必须在 SQL 查询中更改什么才能实现此目的?
最佳答案
MySQL 不支持 GROUPING SETS
,而这正是您真正想要的。也许最简单的方法是使用 UNION ALL
:
SELECT Country, Category, SUM(Revenue) as Revenue, SUM(Costs) as Costs
FROM Pal
WHERE Event_Date BETWEEN '2017-01-01' AND '2017-01-31'
GROUP BY Country, Category
UNION ALL
SELECT NULL, NULL, SUM(Revenue) as Revenue, SUM(Costs) as Costs
FROM Pal
WHERE Event_Date BETWEEN '2017-01-01' AND '2017-01-31';
关于mysql - WITH ROLLUP 结合多个 GROUP BY 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52114152/
我有一张 Excel 表格,用于更新玩家评分。 播放器 配售 初始化 1 2 3 4 金融评级 一个 1 2.0 1.000 0.018 0.016 0.014 2.007 D 2 -2.0 54.5
我有一个 map = std::map ,其中 myItemModel继承QAbstractItemModel . 我现在要合并所有 myItemModel合一myItemModel (其他所有元素模
我大量使用“do.call”来生成函数调用。例如: myfun <- "rnorm"; myargs <- list(n=10, mean=5); do.call(myfun, myargs); 但是
想象一下 InputStream 的以下变体: trait FutureInputStream { //read bytes asynchronously. Empty array means E
这是我的 C 代码: #include void sum(); int newAlphabet; int main(void) { sum();
我只是想选择类“.last”之后的每个元素。 HTML: 1 2 Jquery
我正在为一个项目构建一个 XML 反序列化器,我经常遇到这种类型的代码情况: var myVariable = ParseNDecimal(xml.Element("myElement")) == n
这是来自 Selecting the highest salary 的继续问题 假设有一个表 'wagetable' name lowhours highhours wage pri
我正在为我的程序创建一个战舰程序;该程序运行良好,但我试图确保当用户将坐标超出范围时,程序会说他们输入的坐标不正确。这是代码: #include #include void
我有一个函数,它为每种情况返回不同的 DWORD 值,如果出现错误。所以我有以下定义: #define ERR_NO_DB_CONNECTION 0x90000 #define ERR_DB_N
在派生类中引发基类事件以下简单示例演示了在基类中声明可从派生类引发的事件的标准方法。此模式广泛应用于 .NET Framework 类库中的 Windows 窗体类。在创建可用作其他类的基类的类时,应
我只是想知道这是否可能: use Modern::Perl; my @list = ('a' .. 'j'); map { func($_) } each(@list); sub func { m
我一直在使用 =IF(L2="","Active",IF(K2I2,"Late"))) 有效,但现在我需要检查 F 上的多个条件 专栏 我试过了 OR 函数 =IF(OR(F2="Scheduled"
我有 2 个命令,如下所示。 在视频中添加介绍图片 ffmpeg -y -loop 1 -framerate 10 -t 3 -i intro.png -i video.mp4 -filter_com
好的,我有这个公式可以根据名字和姓氏列表生成用户名。现在,虽然这可行,但我希望单元格改为引用我自己的 VBA 函数。但是,由于代码少得多,我仍然想使用原始公式。 我有这个公式: =SUBSTITUTE
我有两个 HAProxy 实例。两个实例都启用了统计信息并且工作正常。 我正在尝试将两个实例的统计信息合并为一个,以便我可以使用单个 HAProxy 来查看前端/后端统计信息。我试图让两个 hapro
我有一个 Observable,其中每个新值都应该引起一个 HTTP 请求。在客户端,我只关心最新的响应值;但是,我希望每个请求都能完成以进行监控/等。目的。 我目前拥有的是这样的: function
我的网站上有 TinyMCE 插件。在 TinyMCE 插件的 textarea 中添加图像时,我希望这些图像包含延迟加载。我网站的缩略图具有特定类型的延迟加载,其中 src 图像是灰色背景。根据用户
我希望合并润滑间隔,以便如果它们重叠,则从内部第一个时间获取最小值和从内部最后一个时间获取最大值并总结以创建一个跨越整个时间段的新间隔。这是一个reprex: library(lubridate, w
我有一个应用程序,它本质上是一个页眉、主要内容和一个始终可见的页脚。页脚可以改变大小,我想在页脚上方的主内容面板上放置一些工具。主要布局是用 flex 完成的,我阅读文档的理解是绝对定位通过相对于最近
我是一名优秀的程序员,十分优秀!