查询按字段中的最后一个字符选择分组 [英] Query Select group by last character in field

查看:57
本文介绍了查询按字段中的最后一个字符选择分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在表上进行查询搜索,并返回以相同字符结尾的行数.例如,Cd312a,fdhEA和42dA将被组合在"A"下.以下是表格的示例以及我希望看到的返回结果.

I'm trying to go a query search on a table and return a count of rows that end in the same character. For example Cd312a, fdhEA and 42dA would be grouped together under 'A'. Below is an example of the table and what I would like to see returned.

表Tbl_Table

Table Tbl_Table

ID| _Name     |
1 | S033114A  |
2 | S033114B  |
3 | S033114B  |
4 | S033114K  |
4 | S033114K  |  

结果

Type  | Count
  A   |  1
  B   |  2
  K   |  2 

我当前的代码

SELECT RIGHT(_Name,1) as Type, Count(Type) as Count FROM Tbl_Table

任何可以了解我的查询的人都没有返回我期望的结果.谢谢.

Anyone that can shed some light on my my query isn't returning what I am expecting would be helpful. Thank you.

推荐答案

之前

SELECT RIGHT(_Name,1) as Type, Count(Type) as Count
FROM Tbl_Table

之后

SELECT RIGHT(_Name,1) as Type, Count(*) as Count
FROM Tbl_Table
Group by RIGHT(_Name,1)
Order by RIGHT(_Name,1)

修改

从计数"功能中删除了类型",以解决字段列表中的未知列'类型'"问题.

Removed "Type" from the Count function to address the "Unknown column 'Type' in 'field list'" problem.

这篇关于查询按字段中的最后一个字符选择分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆