gpt4 book ai didi

mysql - 将列值/字段/行从一个表复制到另一个表

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

我有一个名为data_table的表,其中有一个列名称status并且有一个列值或字段pendingapproved 我想将这 2 个字段的计数或总计获取到另一个名为 total_status 的表,该表有一个列 total_pendingtotal_approved

实现该结果的最佳方法是什么?我使用 phpmyadmin 顺便说一句来查询

数据表
|第 1 栏 |第 2 栏 |状态   |
| xxxx     | xxxx     |待处理 |
| xxxx     | xxxx     |已批准|
| xxxx     | xxxx     |已批准|
| xxxx     | xxxx     |待处理 |
| xxxx     | xxxx     |已批准|

click to see table structure

我希望结果如下:

total_status
|待处理总数 |已批准总数 |
| 2            | 3             |

click to see table structure

希望你明白我的意思:)

最佳答案

select 
sum(case when status = 'pending' then 1 end) as total_pending,
sum(case when status = 'approved ' then 1 end) as total_approved
from data_table

关于mysql - 将列值/字段/行从一个表复制到另一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32496425/

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