SQL查询:获取表的总记录. [英] SQL Query: Get total records for a table.

查看:67
本文介绍了SQL查询:获取表的总记录.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我想获得一个SQL查询,询问如何获取除一条记录以外的表中的总记录.那是假定的,我有100条记录,但我只想要99条记录.

除记录外,该记录可能不是最后的.如果那必须是最后一个告诉我该如何写,也请您尽快给予答复.


谢谢,
k sunitha


[原始标题]
我想获取表1的总记录的Sql查询.这意味着除最后一条记录外的所有记录.例如,有99条记录,但我只希望98条记录.

Hi friends,

I would like to get an SQL query for How to get a total records in a table except one record. That is suppose, I have 100 records but I want 99 only.

That except record may not be last. If that must be last tell me how to write for that also will you please give reply for that as early as possible.


Advanced thanks,
k sunitha


[orig. title]
i would like to get a Sql Query for total records of a table-1. That means all records except last record.for example,99 records is there but i want 98 only.

推荐答案

我没有对此进行测试,但这可能有效:

I did not test this, but this may work:

Select Top (Select Count(*) From Table - 1) From Table



不清楚是只需要记录的总数-1(即COUNT(*)-1),还是要获得除一个记录以外的所有记录的数据.

假设您需要记录,然后必须确定WHERE子句的正确条件.例如,如果您不想包括最后添加的行,并且表中有一个名为ID的IDENTITY字段,则选择内容可能类似于:
Hi
It''s bit unclear if you want just the total amount of records - 1 (which would be simply COUNT(*) - 1) or if you want to have the data from all records except one.

Let''s say you need the records then you have to decide the correct condition for the WHERE clause. For example if you don''t want to include the last row added and you have an IDENTITY field called ID in the table then the select could be something like:
SELECT *
FROM MyTable
WHERE Id < (SELECT MAX(Id)
            FROM MyTable)


如果要表中的记录总数,请执行以下操作:

从[表名]中选择Count(*)作为总计

如果要Total -1,请执行以下操作:

从[表名]中选择Count(*)-1作为Total

如果您想要设定条件的记录总数,请执行以下操作:

从[表名]中选择Count(*)作为总计,其中[字段] = 0-无论您的状况如何

因此,在这种情况下,我要对表中具有其字段值为0
的所有记录进行计数
希望这能解决您的问题
If you want the total records in a table do:

select Count(*)as Total from [tablename]

If you want Total -1 do:

select Count(*)-1 as Total from [tablename]

If you want the total of records for a set criteria do:

select Count(*) as Total from [tablename] where [Field]=0 --whatever your condition may be

so in this case I am counting all records in the table having my field with a value of 0

Hope this solves your problem


这篇关于SQL查询:获取表的总记录.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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