如何正确使用选择计数(*)为 [英] How to properly use Select count(*) as

查看:63
本文介绍了如何正确使用选择计数(*)为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的一个程序中使用了一个SQL Select语句(我在某处盲目地从网上掠夺)但实际上我并没有完全理解这个语句,似乎无法在任何地方得到解释(包括W3Schools我在哪里做了很多学习)



I am using an SQL Select statement in one of my programs (something I pillaged blindly from the web somewhere) but in truth I don't actually understand the statement completely and cannot seem to get an explanation anywhere (including W3Schools where I do a lot of learning)

Ssql = "SELECT Count(*) as NoOfJustifyRecs FROM Purchase_Justify WHERE PJ_Po_Number = '" & cbo_Order_Number.Text & "'"

       da = New OleDb.OleDbDataAdapter(Ssql, cn)
       da.Fill(ds, "NoOfJustifyRecs")

       cn.Close()


       If ds.Tables("NoOfJustifyRecs").Rows.Count = 0 Then
            ' do something
       End If





有人可以向我解释使用'as NoOfJustifyRecs'吗?

理想情况下,我想说一些像





Could someone please explain to me the use of 'as NoOfJustifyRecs' ?
Ideally I would like to say something like

If NoOfJustifyRecs = 0 then
  '  do something
EndIf





但很明显没有声明NoOfJustifyRecs。



我的大问题是使用'AS NoOfJustifyRecs'是什么意思或使用当我的代码代表时我可以简单地得到来自数据集的值。



谢谢大家。



but obviously NoOfJustifyRecs is not declared.

My big question is what is the point or use of using 'AS NoOfJustifyRecs' when as my code stands I can simply get the value from the dataset.

Thanks guys.

推荐答案

当我们运行计数(*)时在sql server中任何其他函数的语句,我们得到结果,{no column name}作为结果的列标题。通过使用'AS NoOfJustifyRecs',您将得到带有名为'NoOfJustifyRecs'的列标题的计数。



在AdventureWorks DB上运行以下内容......



从Person.StateProvince中选择计数(*)



结果将是---

(无栏名)

181



从Person.StateProvince选择计数(*)为NoOfJustifyRecs



结果将是---

NoOfJustifyRecs

181





希望你现在明白..

如果您有任何疑问,请告诉我。
when we run a count(*) statement of any other function in sql server, we get the result with {no column name} as column header of result. By using 'AS NoOfJustifyRecs' you will get the count with column header named as 'NoOfJustifyRecs'.

Run the following on AdventureWorks DB......

select count(*) from Person.StateProvince

Result will be---
(no column name)
181

select count(*) as NoOfJustifyRecs from Person.StateProvince

Result will be---
NoOfJustifyRecs
181


Hope you understand now..
If you have any doubt, please let me know.


这篇关于如何正确使用选择计数(*)为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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