gpt4 book ai didi

mysql - 客户交易总额

转载 作者:行者123 更新时间:2023-11-29 08:57:11 24 4
gpt4 key购买 nike

我有一个带有购买表的 mysql 数据库:

1   Deal Certificate    int(3)  
2 Purchase Price decimal(4,2)
3 Purchase Date timestamp
4 Serial Number varchar(9)
5 Name varchar(23)
6 Email varchar(42)

运行以下查询后:

 SELECT * 
FROM `PURCHASES`
WHERE `Purchase Date`
between '2012-01-01' and '2012-01-31'
order by email

我看到结果:

345     36.00   2012-01-17 16:42:33     7757-3097   T T     xxx@gmail.com
327 6.00 2012-01-05 10:40:57 0223-3945 R T yyy@gmail.com
329 12.00 2012-01-02 04:54:45 1087-7072 P B zzz@msn.com
294 7.00 2012-01-02 04:59:11 4144-2426 P B zzz@msn.com
285 6.00 2012-01-02 05:12:39 8027-1641 P B zzz@msn.com
1079 21.00 2012-01-02 05:05:07 2447-7971 P B zzz@msn.com
331 10.00 2012-01-02 19:14:38 3916-5434 y a aaa@aol.com

我的问题是,我如何编写一个查询来在一行中汇总该月的每个购买量,以便得到如下所示的结果?

345     36.00   2012-01-17 16:42:33     7757-3097   T T     xxx@gmail.com
327 6.00 2012-01-05 10:40:57 0223-3945 R T yyy@gmail.com
329 46.00 2012-01-02 04:54:45 1087-7072 P B zzz@msn.com
331 10.00 2012-01-02 19:14:38 3916-5434 y a aaa@aol.com

请注意,用户 P B 的所有交易总计在一行中。

谢谢

最佳答案

未经验证:

SELECT  `Deal Certificate`,
sum(`Purchase Price`) as sum_price
`Purchase Date`,
`Serial Number`,
Name,
Email
FROM PURCHASES
WHERE Purchase Date between '2012-01-01' and '2012-01-31'
group by `Deal Certificate`
order by email

关于mysql - 客户交易总额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9655852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com