列中的项目数? (SQL) [英] Count items in column? (SQL)

查看:85
本文介绍了列中的项目数? (SQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

我正在使用Microsoft SQL Server 2005

我有一个这样的表:

 QueueNo 
3B001
3B002
3B003
3G004
3G005
2P001
2G002
2P003
1P001





我想创建一个新表,计算所有以'3','2'和'1'开头的表? />
也许像这样的表:

 QueueInitial Count 
3 < span class =code-digit> 5
2 3
1 1





提前超级感谢!

解决方案

尝试:

  SELECT   LEFT (QueueNo, 1  AS  QueueInitial,COUNT(*) AS  [Count] 
FROM MyTable
GROUP BY LEFT (QueueNo, 1


试试这样:



 选择 substring(QueueNo, 0  2  as  QueueInitial,
count(QueueInitial) as 计算
来自 Your_Table_NAME
group < span class =code-keyword> by substring(QueueNo, 0 2





//您可以创建新的表或临时表并将结果插入

试试这个。



选择子串(QueueNo,1,1)作为QueueInitial,count(QueueInitial)作为Count
来自Table_NAME的






group by substring(QueueNo,1,1)


Hello!
I am using Microsoft SQL Server 2005
I have a table like this:

QueueNo
 3B001
 3B002  
 3B003 
 3G004
 3G005  
 2P001
 2G002
 2P003  
 1P001



I want to make a new table that counts all the ones that start with '3','2', and '1'?
Maybe a table like this:

QueueInitial    Count
     3            5
     2            3
     1            1



Super thanks in advance!

解决方案

Try:

SELECT LEFT(QueueNo,1) AS QueueInitial, COUNT (*) AS [Count]
FROM MyTable
GROUP BY LEFT(QueueNo,1)


Try like this :

select substring(QueueNo,0,2) as QueueInitial    ,
            count(QueueInitial) as Count
 from Your_Table_NAME
group by substring(QueueNo,0,2)



//You can create new table or temp table and insert the result in that


Try this.

select substring(QueueNo,1,1) as QueueInitial,count(QueueInitial) as Count

from Table_NAME

group by substring(QueueNo,1,1)


这篇关于列中的项目数? (SQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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