bitscn.com
一条mysql语句引发的思考
今天看到同事写的一条mysql语句,居然没有完全看懂,顿时感觉到差距,在我的思维里,mysql语句只是增、删、查、改,原来还可以这样写。
[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);
像这个cast、substri ng,真是没见过这样写过。
查了一下手册,又有一个函数convert和它差不多。
cast(value as type); convert(value ,type);
type不是都可以滴,可以转换的type如下:
二进制,同带binary前缀的效果 : binary
字符型,可带参数 : char()
日期 : date
时间: time
日期时间型 : datetime
浮点数 : decimal
整数 : signed
无符号整数 : unsigned
看来还是得多看手册啊。
bitscn.com
