當前位置:首頁 » 編程語言 » 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

修改逗表名地為實際需要查詢的表名即可