首頁  >  文章  >  資料庫  >  mysql:最实用的sql语句_MySQL

mysql:最实用的sql语句_MySQL

WBOY
WBOY原創
2016-06-01 13:35:511015瀏覽

bitsCN.com

mysql:最实用的sql语句

 

1.把catalog_product_entity_text表字段里面的

UPDATE `catalog_product_entity_text` SET `value` = REPLACE(`value`, '

 

2.给表添加一个列

 

ALTER TABLE `isc_product_tags`  ADD `bigtags`  VARCHAR(20) 

 

(1)删除多余的行数  www.bitsCN.com  

delete FROM `isc_product_tags` WHERE `tagname`=''

 

3.删除表的数据

TRUNCATE TABLE `directory_country`

 

4.关联查找tags表里的tags的相关的其他tags:

 

(1)查找tags表里的tags的相关的其他tags:

SELECT * FROM `isc_product_tags` WHERE `bigtags`=(SELECT `bigtags` FROM `isc_product_tags`  WHERE `tagfriendlyname`='720p-car-dvr') and `tagfriendlyname` !=  '720p-car-dvr' ORDER BY  'tagname' DESC;

 

 

(2)查找某个产品的所有关联tags:

SELECT * FROM `isc_product_tags` WHERE `tagid`in(SELECT `tagid` FROM  `isc_product_tagassociations` WHERE `productid`=(SELECT `productid` FROM `isc_products` WHERE `prodname`='Mega Pixel 720p HD IR Array Waterproof Network TF Storage Camera'))

 

SELECT * FROM `isc_product_tags` WHERE `tagid` in(SELECT `tagid` FROM  `isc_product_tagassociations` WHERE `productid`=(SELECT `productid` FROM `isc_products`  WHERE `prodname`='5 Megapixel Sensor Full HD 1080P Outdoor IP Camera 120m IR Night View '))  ORDER BY tagname ASC

 

5.更改产品价格:

UPDATE`isc_products` SET `prodretailprice` = '92.0000', `prodsaleprice`='69.0000' WHERE  `productid` =1605;

 

6.导入导出数据库命令:(bin目录下)

导出:mysqldump -u root -p bokele >c:/mysql.sql --default-character-set=utf8

导入:C:/mysql/bin/> mysql -u root -p

说明:C:/mysql/bin/表示进入mysql程序根目录

 

C:/helloapp/schema/sampledb.sql是要导入数据库的文件的位置

c:/mysql.sql是导出的sql文件

--default-character-set=utf8 指编码方式

 

7.建新表

CREATE TABLE IF NOT EXISTS `isc_pluginproduct_association` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `main_cat_id` int(11) NOT NULL,

  `product_id` int(11) NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=66 ;

 

INSERT INTO `isc_pluginproduct_association` (`id`, `main_cat_id`, `product_id`) VALUES

(65, 31, 24),

(64, 31, 18),

(63, 31, 23),

(62, 32, 24),

(61, 32, 23),

(60, 32, 28),

(51, 38, 26),

(16, 36, 14),

(15, 36, 15),

(50, 38, 23),

(49, 38, 22),

(48, 38, 21),

(47, 38, 20),

(46, 38, 18),

(45, 38, 16),

(44, 38, 12),

(43, 38, 10),

(42, 38, 15),

(41, 38, 17),

(40, 38, 13),

(57, 39, 16),

(56, 39, 15),

(55, 39, 14);

 

8.多个and条件的查询语句

(1)myphp的sql语句:

SELECT * 

FROM  `isc_products` 

WHERE  `prodcode` =  'IP-Z0144'

AND  `prodname` LIKE  '%Tilt WiFi %'

AND  `prodprice` = 144.00

LIMIT 0 , 30

 

9.把产品名字中的特殊符号和空格替换为-号,查找产品

SELECT * FROM `isc_products` WHERE 

`prodname` like '%5%'

and `prodname` like '%Megapixels%'

and `prodname` like '%1%'

and `prodname` like '%2.5%'

and `prodname` like '%Sensor%'

and `prodname` like '%720P%'

and `prodname` like '%Outdoor%'

and `prodname` like '%IP%'

and `prodname` like '%Camera%'

and `prodname` like '%40m%'

and `prodname` like '%IR%'

and `prodname` like '%Night%'

and `prodname` like '%View%'

 

10.写一个数据库的语句:将A表里,B字段中第一个C字符替换成D

 

(1) 查询`isc_search_corrections`表的`correction`字段的首字母

 

SELECT SUBSTRING(`correction`,1,2) FROM `isc_search_corrections`

 

(2) 更新:`isc_search_corrections`表,`correction`字段含有首字母C的替换首字母为D

 

UPDATE `isc_search_corrections` SET `correction` = REPLACE(`correction`, 'C', 'D') WHERE  SUBSTRING(`correction`,1,2)='C'

 

bitsCN.com

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn