常用的sql语句
时间转换
SELECT UNIX_TIMESTAMP( '2014-05-01 00:00:00 ' )
SELECT FROM_UNIXTIME( 1249488000, '%Y-%m-%d' )
去掉字符串中中括号及内容
UPDATE 表名 SET 字段名=CONCAT(LEFT(字段名,INSTR(字段名,'[')-1),RIGHT(字段名,LENGTH(字段名)-INSTR(字段名,']')))
WHERE INSTR(字段名,'[')>0 AND INSTR(字段名,']')>INSTR(字段名,'[')
mysql连接多个字段数据到一个字段中
update CM_CUST set CUST_NAME_CN= concat(CUST_NAME_CN,'(',CERTIFICATE_NO,TELPHONE,')')
其中:CUST_NAME_CN,CERTIFICATE_NO,TELPHONE为表CM_CUST中的三个字段
mysql一个字段拆分为多个字段
SELECT SUBSTRING( refund_product, 1, LOCATE( 'x', refund_product ) -1 ) AS province, SUBSTRING( refund_product, LOCATE( 'x', refund_product ) +1 ) AS city
FROM 000_jeff_refund_1
查询一个字段多个纪录到一个结果集
SELECT `product_id`,GROUP_CONCAT(`ebay_item_id` separator '|') `ebay_item_id` FROM `ebay_item_variation` WHERE `product_id`=201 group by `product_id`