Thoughts on a Mysql statement bitsCN.com
Thoughts on a Mysql statement
Today, I saw a mysql statement written by my colleagues, but I didn't fully understand it. I suddenly felt the gap. in my mind, mysql statements only add, delete, query, and modify them, you can still write it like this.
[Php]
$ SQL = "SELECT category_general_table
FROM product_category
WHERE category_id IN
(SELECT DISTINCT
CAST (SUBSTRING (product_code, 1, 5) as unsigned) AS cid
FROM product_index
WHERE member_id = $ memberId AND shop_id = $ shopId )";
I have never written it like this CAST or SUBSTRI NG.
After checking the manual, another function CONVERT is similar to it.
Cast (value as type); Convert (value, type );
Not all types can be dropped. the type that can be converted is as follows:
Binary, with a BINARY prefix: binary
Character type, with parameters: CHAR ()
DATE: DATE
TIME: TIME
DATETIME type
Floating point: DECIMAL
Integer: SIGNED
UNSIGNED integer
It seems that I still have to read more manuals.
BitsCN.com