gpt4 book ai didi

sql - 如何统计Oracle数据库中首字母相同的行数

转载 作者:搜寻专家 更新时间:2023-10-30 19:55:32 25 4
gpt4 key购买 nike

我有一张客户表:

╔════════════╦═════╗
║ CustomerID ║ ... ║
╠════════════╬═════╣
║ ACC20011 ║ ... ║
║ ACC30122 ║ ... ║
║ ACC12356 ║ ... ║
║ EVG12345 ║ ... ║
║ DAA23445 ║ ... ║
║ DAA23548 ║ ... ║
╚════════════╩═════╝

我需要以下输出:

╔════════════╦═══════╗
║ CustomerID ║ Count ║
╠════════════╬═══════╣
║ Acc ║ 3 ║
║ EVG ║ 1 ║
║ DAA ║ 2 ║
╚════════════╩═══════╝

我写了以下查询。但我知道错了。请指正。

select CustomerID , count(*) as Count 
from Customers
where CustomerID is like 'ACC%'

最佳答案

试试这个查询:

SELECT SUBSTR(CustomerID, 1, 3) AS CustomerID, COUNT(*)
FROM Customers
GROUP BY SUBSTR(CustomerID, 1, 3)

关于sql - 如何统计Oracle数据库中首字母相同的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33753261/

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