count(1)返回0? [英] count(1) return 0?

查看:143
本文介绍了count(1)返回0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


是否可以获得一个count(1)状态,例如:


select count(1)从结果中,夹具= 4916,胜者=远离胜利者组;


如果没有匹配夹具= 4916

则返回0值而不是绝对没有和胜利者=离开?我完全没有结果。

从结果中选择count(1),其中fixture = 4916,wins = home group by winner;

count

-------

(0行)


有什么想法吗?


谢谢


ciao


Zak


-

== ================================================ == ====================
http://www.carfolio.com/ 可搜索的10 000多辆汽车规格数据库

=================== =============================== =================== ===


---------------------------(播出结束)--- ------------------------

提示1:订阅和取消订阅命令转到 ma ******* @ postgresql.org

解决方案

Zak McGregor写道:

大家好

是不是可能le得到一个count(1)statemment,例如这里:

从结果中选择count(1),其中fixture = 4916,wins = away group by winner;

to如果没有行匹配fixture = 4916
和winner = away,则返回0值而不是绝对没有值?我完全没有任何结果。

从结果中选择count(1),其中fixture = 4916,wins = home group by winner;
count
------ -
(0行)

有什么想法吗?




不确定我明白你想要什么,但试试像这个:


当count(*)>时选择大小写0然后'''''''''''''''''''''''''''''''''''''''''''

潜在技术
http://www.potentialtech.com

---------------------------(广播结束)------- --------------------

提示3:如果通过Usenet发布/阅读,请发送适当的

subscribe-nomail命令 ma*******@postgresql.org 以便您的

消息可以干净地通过邮件列表


On Sun,2004年2月29日19:55:15 -0500

Bill Moran< wm **** @ potentialtech.com>写道:

不确定我理解你想要什么,但尝试这样的事情:

当count(*)>时选择案例0然后''''''''''''''''''''''''''''''''''''''''''''''当结果集中没有任何记录

时,我根本就没有行 - 所以在案例中......除了
中的某种表达式,选择本身也可以。


我正在寻找的是一种选择0的方法。如果没有返回任何行,或者从查询返回的行总数为




不过感谢你。


Ciao


Zak


-

========== ======================================== ========== ============
http://www.carfolio .com / 可搜索的10 000多辆汽车规格数据库

=========================== ======================= ======================


---------------------------(广播结束)----------- ----------------

提示5:您是否检查了我们广泛的常见问题解答?

http://www.postgresql.org/docs/faqs/FAQ.html


Zak McGregor写道:

On Sun,2004年2月29日19:55:15 -0500
Bill Moran< wm ****@potentialtech.com>写道:

不确定我理解你想要什么,但尝试这样的事情:

当count(*)>时选择案例0然后'''''''''''''''''''''''''''''''''''''''''


不幸的是,这不起作用。当结果集中没有任何记录时,我根本就没有行 - 所以在案例中......其他表达式中的选择本身也会有效。

我是什么我正在寻找一种选择0的方法。如果没有返回行,或者从查询返回的总行数。否则。




我怀疑我还是不明白你是什么''尝试这样做,但是......


当count(*)>时选择案例0然后1其他0结束...


我应该建议的。


-

Bill Moran

潜在技术
http://www.potentialtech .com

---------------------------(播出结束)---- -----------------------

提示5:您查看了我们广泛的常见问题解答吗?

< a rel =nofollowhref =http://www.postgresql.org/docs/faqs/FAQ.htmltarget =_ blank> http://www.postgresql.org/docs/faqs/FAQ.html


Hi all

is it possible to get a count(1) statemment, for example here:

select count(1) from results where fixture=4916 and winner=away group by winner;

to return a 0 value instead of absolutely nothing if no rows match fixture=4916
and winner=away? I get absolutely no results at all.
select count(1) from results where fixture=4916 and winner=home group by winner;
count
-------
(0 rows)

any ideas please?

Thanks

ciao

Zak

--
================================================== ======================
http://www.carfolio.com/ Searchable database of 10 000+ car specs
================================================== ======================

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

解决方案

Zak McGregor wrote:

Hi all

is it possible to get a count(1) statemment, for example here:

select count(1) from results where fixture=4916 and winner=away group by winner;

to return a 0 value instead of absolutely nothing if no rows match fixture=4916
and winner=away? I get absolutely no results at all.
select count(1) from results where fixture=4916 and winner=home group by winner;
count
-------
(0 rows)

any ideas please?



Not really sure I understand what you want, but try something like this:

select case when count(*) > 0 then ''''t'''' else ''''f'''' end from ...

--
Bill Moran
Potential Technologies
http://www.potentialtech.com
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly


On Sun, 29 Feb 2004 19:55:15 -0500
Bill Moran <wm****@potentialtech.com> wrote:

Not really sure I understand what you want, but try something like this:

select case when count(*) > 0 then ''''t'''' else ''''f'''' end from ...



Unfortunately that does not work. When the resultset contains no records
whatsoever, I get no rows at all - so on case...else sort of expression within
the select itself will work.

What I am looking for is a way to select "0" if no rows are returned, or the
total number of rows returned from the query otherwise.

Thanks anyways though.

Ciao

Zak

--
================================================== ======================
http://www.carfolio.com/ Searchable database of 10 000+ car specs
================================================== ======================

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Zak McGregor wrote:

On Sun, 29 Feb 2004 19:55:15 -0500
Bill Moran <wm****@potentialtech.com> wrote:

Not really sure I understand what you want, but try something like this:

select case when count(*) > 0 then ''''t'''' else ''''f'''' end from ...



Unfortunately that does not work. When the resultset contains no records
whatsoever, I get no rows at all - so on case...else sort of expression within
the select itself will work.

What I am looking for is a way to select "0" if no rows are returned, or the
total number of rows returned from the query otherwise.



I suspect that I still don''t understand what you''re trying to do, but ...

select case when count(*) > 0 then 1 else 0 end from ...

Was what I should have suggested.

--
Bill Moran
Potential Technologies
http://www.potentialtech.com
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


这篇关于count(1)返回0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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