| |

VerySource

 Forgot password?
 Register
Search
View: 1550|Reply: 5

Today I discovered the difference between select count (1) and select count (column name)

[Copy link]

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-2 17:30:01
| Show all posts |Read mode
select count (1) into: str2 from "tongji"
where "xfdate" =: tjrqd and "cardnum" =: str1;

select count (xftime) into: str2 from "tongji"
where "xfdate" =: tjrqd and "cardnum" =: str1;

If no data is retrieved, the return value of sqlcode is different.

The return value of count (1) is empty and sqlcode is 100
The return value of count (column name) is 0 and sqlcode is 0

Which one to talk about?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-2 21:09:01
| Show all posts
count () in the sql statement is the total number of statistics records, () can be a field name or *

If you use 1, you don't have this field in your table, so it returns null

When the sqlcode value is 100, the executed SQL statement did not return any results
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-4 18:15:01
| Show all posts
Different databases have different effects, right?
I use Sybase ASE and Sybase ASA
Whether count (*) or count (1)
Return value when no data is retrieved: 0
Reply

Use magic Report

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-1-5 09:03:01
| Show all posts
I use ASA 8.0
Reply

Use magic Report

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-1-5 09:24:01
| Show all posts
Strange, I tried to interview in isql, and I also saw 0. Is my code wrong?
Reply

Use magic Report

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-5-8 11:30:01
| Show all posts
Found the reason, select count (), the column name needs group by, then the return code 100 will appear when the record is not found, count (1) count (column name)
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list