我可以用这种方式计数行吗?
SELECT COUNT(SERVICE_TYPE) INTO N_CNT FROM (
SELECT RECIPIENT, SERVICE_TYPE, MPS_SWTCH_CD, MPS_FTR_CD1 FROM ABA_RM_INB_USAGE
WHERE SERVICE_TYPE = 100 AND
MPS_SWTCH_CD = 'T11' AND
MPS_FTR_CD1 = 1033);
答案 0 :(得分:0)
您可以像这样计算行而不是列,关键字INTO是多余的,如果我修改查询,如下所示,
SELECT COUNT(SERVICE_TYPE) N_CNT FROM (
SELECT RECIPIENT, SERVICE_TYPE, MPS_SWTCH_CD, MPS_FTR_CD1 FROM ABA_RM_INB_USAGE
WHERE SERVICE_TYPE = 100 AND
MPS_SWTCH_CD = 'T11' AND
MPS_FTR_CD1 = 1033)a;
您也可以在没有子查询的情况下进行计数
SELECT Count(*) N_CNT
FROM ABA_RM_INB_USAGE
WHERE SERVICE_TYPE = 100 AND
MPS_SWTCH_CD = 'T11' AND MPS_FTR_CD1 = 1033;
答案 1 :(得分:0)
如另一个答案中所述,您的语句用于计数行。如果您想计算表的列数,请尝试如下操作。
请参见this post
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_catalog = 'database_name' -- the name of your database
AND table_name = 'table_name' -- the table you want to count columns in