如何计算(选择一些表格)

时间:2018-03-01 02:05:57

标签: sql sql-server

SELECT TABLENAME
FROM BASE5.SYS_FORM_INFO
where ISFLAG = 1

结果:

enter image description here

当我使用count()来包含它时。

SELECT count(*) from (
    SELECT TABLENAME
    FROM BASE5.SYS_FORM_INFO
    where ISFLAG = 1
)

结果:

[Err] 42000 - [SQL Server]')'

附近的语法错误
SELECT count(*) from FE_APP5.dbo.FT_001_84D7B91BDD9F26F2178E

结果:

enter image description here

所以,我的问题是如何计算我选择的一些表格?

1 个答案:

答案 0 :(得分:3)

您需要子查询的别名:

SELECT count(*) as cnt
FROM (SELECT TABLENAME
      FROM BASE5.SYS_FORM_INFO
      WHERE ISFLAG = 1
     ) x;

我假设您知道子查询不是必需的:

SELECT COUNT(*) as cnt
FROM BASE5.SYS_FORM_INFO
WHERE ISFLAG = 1