如何在Mysql中使用Count()检查数据库中的记录数 [英] How Do I Check No. Of Records In Database Using Count() In Mysql
本文介绍了如何在Mysql中使用Count()检查数据库中的记录数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查条件BE_BookIssuestatus ='A'使用计数
我的查询如下
SELECT CASE WHEN 计数(BE_BookIssuestatus IN (' A'))> 0 那么 ' Available' ELSE ' 不可用' END BookStatus 来自 BookEntity_Master
返回可用当表中BE_BookIsseStatus不等于'A'时,如果没有BookIsseStatus'A'
解决方案
更改为(使用ISNULL)
SELECT CASE WHEN ISNULL(计数(BE_BookIssuestatus IN (' A')), 0 跨度> )> 0 那么 ' Available' ELSE ' 不可用' END BookStatus 来自 BookEntity_Master
我会用子查询来做它。
我会假设有某种ID列。
我不喜欢我知道,在这种情况下,MS SQL SERVER是否与MySQL不同,但这里有一个提示。
SELECT CASE ISNULL(A.QT,0)WHEN 0那么'不可用'ELSE'可用'END AS BookStatus来自BookEntity_Master
LEFT OUTER JOIN(SELECT ID,Count(*)AS QT from BookEntity_Master WHERE BE_BookIssuestatus IN('A')GROUP BY ID)AS A
ON A.ID = BookEntity_Master.ID
I Want to Check the condition for BE_BookIssuestatus='A' using count
my query as follows
SELECT CASE WHEN Count(BE_BookIssuestatus IN('A')) > 0 THEN 'Available' ELSE 'Not Available' END BookStatus from BookEntity_Master
It returns Available When there is BE_BookIsseStatus not equal to 'A' in table,Any Suggestion for this to obtain 'Not Available' when there is no BookIsseStatus 'A'
解决方案
change into (use of ISNULL)
SELECT CASE WHEN ISNULL(Count(BE_BookIssuestatus IN('A')),0) > 0 THEN 'Available' ELSE 'Not Available' END BookStatus from BookEntity_Master
Hi, I woul sugest doing it with a subquery.
I will assume that there is some sort of ID column.
I don't know if, in this case, MS SQL SERVER is that different from MySQL, but here's a hint.
SELECT CASE ISNULL(A.QT, 0) WHEN 0 THEN 'Not Available' ELSE 'Available' END AS BookStatus FROM BookEntity_Master
LEFT OUTER JOIN (SELECT ID, Count(*) AS QT FROM BookEntity_Master WHERE BE_BookIssuestatus IN('A') GROUP BY ID) AS A
ON A.ID = BookEntity_Master.ID
这篇关于如何在Mysql中使用Count()检查数据库中的记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文