英文:
how to combine data on same date in sql?
问题
如何在SQL中合并相同日期的数据? 我的数据库表
我的预期结果类似于这样 我期望的结果
英文:
how to combine data on same date in sql? my database table
my expected result is something like this the result I expected
答案1
得分: 0
你可以在日期字段上使用"GROUP BY"语句:
create table SOQ4
(
ops_date date,
well_profit int,
well_loss int
);
insert into SOQ4 values
('2018-02-28', 0, 163),
('2018-02-28', 453, 0),
('2018-02-28', 0, 0),
('2018-03-31', 0, 228),
('2018-03-31', 469, 0),
('2018-03-31', 0, 0),
('2018-04-30', 0, 226),
('2018-04-30', 424, 0),
('2018-04-30', 0, 0);
SELECT
ops_date,
SUM(well_profit) AS well_profit,
SUM(well_loss) AS well_loss
FROM
SOQ4
GROUP BY
ops_date;
英文:
You can use group by statement on the date
create table SOQ4
(
ops_date date,
well_profit int,
well_loss int
);
insert into SOQ4 values
('2018-02-28',0,163),
('2018-02-28',453,0),
('2018-02-28',0,0),
('2018-03-31',0,228),
('2018-03-31',469,0),
('2018-03-31',0,0),
('2018-04-30',0,226),
('2018-04-30',424,0),
('2018-04-30',0,0);
SELECT
ops_date,
SUM(well_profit) AS well_profit,
SUM(well_loss) AS well_profit
FROM
SOQ4
GROUP BY
ops_date;
Output:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论