当前位置:首页 » 编程语言 » sql查字段数
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql查字段数

发布时间: 2022-08-07 23:54:46

sql中如何查看某一字段值有几个数值

用分组,组内计数就可以了,意思就是根据字段a的取值进行分组,相同的为一组,在用count进行组内计数select a,count(*)from Agroup by a

⑵ SQL查询字段数量

select COUNT(a.name) from sys.all_columns a,sys.tables b
where a.object_id=b.object_id and b.name='table_name'

⑶ sql 查询 不同字段的数量

请参考下列sql语句:

select
(select count(*) from tblName
where type=100) as QtyAt100,
(select count(*) from tblName
where type=101) as qtyAt101;

或者

select
sum(case type when 100 then 1 else 0 end) as QtyAt100,
sum(case type when 101 then 1 else 0 end) as QtyAt101 from tblName
where type=100 or type=101;

⑷ sql 查询怎么统计多个字段各自的个数

--所有算的地方都用cast(个数asint)
createtabletest05
(avarchar(10),
bvarchar(10),
cvarchar(10))

insertintotest05select'#','一','三'unionall
select'@','一','三'unionall
select'¥','一','二'unionall
select'%','二','二'
select*fromtest05

selectb,COUNT(b)个数fromtest05groupbyb
selectc,COUNT(c)个数fromtest05groupbyc

selectSUM(isnull(t1.个数,0)+isnull(t2.个数,0))总数,sum(isnull(t1.个数,0))个数,t1.b,sum(isnull(t2.个数,0))个数,t2.cfrom
(selectb,COUNT(b)个数fromtest05groupbyb)ast1fulljoin
(selectc,COUNT(c)个数fromtest05groupbyc)ast2ont1.b=t2.c
groupbyt1.b,t2.c

⑸ 如何统计SQL中某字段总数和符合某条件的数量

输入代码

select 名称
,count(*) as 总数量
,count(case when 类型='A' then 类型 else null end) as 类型为A的数
from 表名
group by 名称。

就可以统计SQL中某字段总数和符合某条件的数量。

⑹ sql 查询某一字段值的个数

select字段1,count(字段2)个数
fromtabname
groupby字段1

⑺ 怎么用SQL语句得到一个表的字段数

用一个查询打开表后,可以根据TADOQuery控件的FieldCount属性来获得字段个数。
MySql:='Select * From MyTBName ';
ADOQ_Fields.Close;
ADOQ_Fields.SQL.Clear;
ADOQ_Fields.SQL.Add(MySql);
ADOQ_Fields.Open;
SBar.Panels[2].Text:='共计:'+IntToStr(ADOQ_Fields.FieldCount)+'条字段';
如果你想得到每个字估的类型,可以对字段进行一下遍历。
放一个TValueListEditor控件,命名为VLEditor_Fields,用来存放字段信息。

VLEditor_Fields.Strings.Clear;
For i:=0 to ADOQ_Fields.FieldCount-1 DO
Begin
case ADOQ_Fields.FieldByName(ADOQ_Fields.Recordset.Fields.Item[i].Name).DataType of
ftUnknown: FieldType :='ftUnknown';
ftString: FieldType :='ftString';
ftSmallint: FieldType :='ftSmallint';
ftInteger: FieldType :='ftInteger';
ftWord: FieldType :='ftWord';
ftBoolean: FieldType :='ftBoolean';
ftFloat: FieldType :='ftFloat';
ftCurrency: FieldType :='ftCurrency';
ftBCD: FieldType :='ftBCD';
ftDate: FieldType :='ftDate';
ftTime: FieldType :='ftTime';
ftDateTime: FieldType :='ftDateTime';
ftBytes: FieldType :='ftBytes';
ftVarBytes: FieldType :='ftVarBytes';
ftAutoInc: FieldType :='ftAutoInc';
ftBlob: FieldType :='ftBlob';
ftMemo: FieldType :='ftMemo';
ftGraphic: FieldType :='ftGraphic';
ftFmtMemo: FieldType :='ftFmtMemo';
ftParadoxOle: FieldType :='ftParadoxOle';
ftDBaseOle: FieldType :='ftDBaseOle';
ftTypedBinary: FieldType :='ftTypedBinary';
ftCursor: FieldType :='ftCursor';
ftFixedChar: FieldType :='ftFixedChar';
ftWideString: FieldType :='ftWideString';
ftLargeint: FieldType :='ftLargeint';
ftADT: FieldType :='ftADT';
ftArray: FieldType :='ftArray';
ftReference: FieldType :='ftReference';
ftDataSet: FieldType :='ftDataSet';
ftOraBlob: FieldType :='ftOraBlob';
ftOraClob: FieldType :='ftOraClob';
ftVariant: FieldType :='ftVariant';
ftInterface: FieldType :='ftInterface';
ftIDispatch: FieldType :='ftIDispatch';
ftGuid: FieldType :='ftGuid';
ftTimeStamp: FieldType :='ftTimeStamp';
ftFMTBcd: FieldType :='ftFMTBcd';
else FieldType :='';
end;
VLEditor_Fields.InsertRow(ADOQ_Fields.Recordset.Fields.Item[i].Name,FieldType ,True);
End;

⑻ 怎么通过一个sql语句查询一个表中字段的个数

select
a.name
,count(0)字段总数
from
sys.objectsa
innerjoinsys.all_columnsbona.object_id=b.object_id
where
a.type='U'anda.name='表名'
groupby
a.name

修改逗表名地为实际需要查询的表名即可