比较单个查询中两个表的行数并返回布尔值 [英] Compare row count of two tables in a single query and return boolean

查看:25
本文介绍了比较单个查询中两个表的行数并返回布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较两个表的行数,然后根据是否相同返回01.

I want to compare row count of two tables and then return 0 or 1 depending on whether its same or not.

我正在考虑这样的事情,但无法继续前进,需要一些帮助.

I am thinking of something like this but can't move ahead and need some help.

SELECT 
       CASE WHEN (select count(*) from table1)=(select count(*) from table2)
       THEN 1
       ELSE 0
       END AS RowCountResult
FROM Table1,Table2

我得到多行而不是带有 01

I am getting multiple rows instead of a single row with 0 or 1

推荐答案

you have to remove :

you have to remove :

FROM Table1,Table2

否则它将考虑此 FROM 子句的每一行的 Case-When 的结果.

Otherwise it will consider the result of the Case-When for each row of this FROM clause.

这篇关于比较单个查询中两个表的行数并返回布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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