4

In my postgresql query given below and I want to count(completed::float)

select round(Count(completed::float)) as completed,
       assignee 
from NTE_23Apr19_HCMS_DOW_Defects_List_V1 
group by assignee

This is my postgresql table

enter image description here

If I used without float in query it will works but I want to execute with float.Is It possible

select round(Count(completed)) as completed,
       assignee 
from NTE_23Apr19_HCMS_DOW_Defects_List_V1 
group by assignee
4
  • count(completed) and count(completed::float) or even count(completed)::float will all return the same value. What exactly are you trying to do? Maybe you just want count(*)? Commented Apr 24, 2019 at 5:49
  • If I used count(completed)::float instead of count(completed::float).It works Commented Apr 24, 2019 at 6:02
  • Then I have no idea what you are trying to do. count returns an integer, casting that integer to float won't change its value. And counting float values won't return a different count that counting integer values. What exactly does "it works" mean? Do you get an error if it does "not work"? Is your screen shot the result you get or the result you expect? Commented Apr 24, 2019 at 6:07
  • Please edit your question and add a Minimal, Complete, and Verifiable example which should consist of a create table statement, some insert statements and the expected output as formatted text no screen shots please. edit your question do not post code in comments Commented Apr 24, 2019 at 6:07

1 Answer 1

2

There's no such thing as an empty row in PostgreSQL. Your value is either '' (empty string), or a NULL value. You can count those the following ways:

sum(case when completed = '' then 1 else 0 end)

sum(case when completed is null then 1 else 0 end)

better yet:

sum(case when coalesce(completed,'') = '' then 1 else 0 end) - which will cover both situations.

Sign up to request clarification or add additional context in comments.

2 Comments

I want count(decimal),sum(int),avg(float) in above table.If anyone knows please guide me.
You're going to have to add your desired results to your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.