Home > database >  Mysql to return to the field type conversion issues
Mysql to return to the field type conversion issues

Time:11-06

SELECT Id, Type, ItemId, convert (count (*), SIGNED) AS num FROM pointList GROUP BY Id, Type, ItemId,
How such a return num field or the count () function returns the long rather than converted int?

I switch to cast to replace the convert

SELECT Id, Type, ItemId, CAST (count (*) AS SIGNED) AS num FROM pointList GROUP BY Id, Type, ItemId,
Results also long not num type

Please everyone take a look at how to write SQL type int is satisfying num

CodePudding user response:

CodePudding user response:

Cow force!!!!!!!!!!!!!!!!!!!!!!!!

CodePudding user response:

Mysql seems there is no long,,, 4 bytes in general is int, 4 ~ 8 bytes are generally bigint

CodePudding user response:

From the interpretation of the MySQL documentation:

COUNT (expr) [over_clause]

Returns a count of the number of non - NULL values of expr in the rows retrieved by a SELECT statement. The result is a BIGINT value.

https://dev.mysql.com/doc/refman/8.0/en/group-by-functions.html#function_count

CodePudding user response:

Such a change, not sure can, but you can give it a try,
Also want to confirm, the type of this field, where did you see, you should not in SQL, other languages, such as JAVA, type may have differences, and SQL
SELECT Id, Type, ItemId, count (*) + 0 AS num FROM pointList GROUP BY Id, Type, ItemId,

CodePudding user response:

Found the database returned is a string, not binary.
  • Related