国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Database Mysql Tutorial mysql 常用命令之函數(shù)

mysql 常用命令之函數(shù)

Jun 07, 2016 pm 03:33 PM
left mysql function Order Commonly used

函數(shù)如下: left,right 字符串截取 from_unixtime 式化unix時(shí)間戳 concat 字符串連接函數(shù) max 取某列最大 min 取某列最小 sum 計(jì)算某列的和 count 統(tǒng)計(jì)條數(shù) md5 返回md5加密碼的串 format 式化數(shù)字為xx,xxx,xxx.xxxx式 比如1,1000.123 length 計(jì)算某個(gè)字符串

函數(shù)如下:

left,right? 字符串截取
from_unixtime? 格式化unix時(shí)間戳
concat? 字符串連接函數(shù)
max? 取某列最大值
min  取某列最小值?
sum  計(jì)算某列的和
count 統(tǒng)計(jì)條數(shù)
md5  返回md5加密碼的串
format  格式化數(shù)字為xx,xxx,xxx.xxxx格式 比如1,1000.123
length?? 計(jì)算某個(gè)字符串長度
distinct? 去重復(fù)
replace? 替換字符串
in  指定查詢某個(gè)值的記錄
like? 模糊查詢
is null??? 查詢某個(gè)條件為空(null),注:null不等于""
is not null?? 查詢某個(gè)條件不為為空(null)
MATCH ... AGAINST ...???? mysql的全文索引查詢

mysql left,right函數(shù)
left和right是一對(duì)截取字符串前幾位可后幾位的函數(shù),left是從左向右開始計(jì)算,right相反是從右向左計(jì)算
例:
select left(name,10) as name from user; 顯示用戶名的前10位
select right(name,10) as name from user; 顯示用戶名的后10位
select * from user where left(datetime,10)="2011-12-02"??? 取出2011-12-02日注冊(cè)的用戶
select * from user where left(datetime,7)="2011-12"??? 取出2011-12月注冊(cè)的用戶
left,right不僅僅可以用于截取字符串,還可以用在where條件上。特別是用在查詢條件上他的作用非常大。

mysql? from_unixtime函數(shù)
from_unixtime函數(shù)用來對(duì)unix時(shí)間戳進(jìn)行格式化,格式化成我們易讀的日期時(shí)間格式。
例:
select from_unixtime(time, "%Y-%m-%d %H:%i:%s" ) as datetime from table; 把time字段格式化成易讀的日期時(shí)間顯示(time為unix時(shí)間戳)
select *? from table where left(from_unixtime(time, "%Y-%m-%d" ))='2011-12-02' 取出2011-12-02日的記錄

mysql concat 函數(shù)
concat函數(shù) 可以用來把某二個(gè)字符連接在一起查詢或顯示,也可以把字段和字符串進(jìn)行連接。
例:
select concat(year,"-",month,"-",day) as datetime from table; 把表中year,month,day字段連接起來顯示
select concat("My name is:",name) as name from table; 把字符串和字段連接起來顯示
update software set icon=concat("http://iteye.com",icon); 把數(shù)據(jù)庫中icon批量更新并在原有的icon前增加域名 iteye.com

mysql max,min函數(shù)
顧名思義max函數(shù)用于查詢某個(gè)字段中的最大值
例:
select max(age) from user; 返回最大的年齡
select min(age) from user; 返回最小的年齡

?

mysql sum函數(shù)
sum函數(shù) 可對(duì)某個(gè)字符(int型)進(jìn)行求和
例:
select sum(money) from user 計(jì)算出所有人的金錢總數(shù)
select sum(money),area from user group by area 計(jì)算出各地區(qū)人員的金錢總數(shù)


mysql count函數(shù)
統(tǒng)計(jì)聚合函數(shù),可對(duì)sql查詢的結(jié)果進(jìn)行統(tǒng)計(jì)
例:
select count(*) as total from user 計(jì)算出總會(huì)員 iteye.com

mysql md5函數(shù)
同php中的md5一樣,對(duì)某個(gè)字符串進(jìn)行加密
例:
select md5(password) as password from user 把明碼的密碼進(jìn)行md5加密顯示
insert into user(name,password) values("abc",md5("abc")); 寫入user表把密碼進(jìn)行md5加密后存儲(chǔ)

?

mysql format函數(shù)
用于格式化數(shù)字為xx,xxx.xxx格式的數(shù)字
例:
select format(downloads) as download from software; 把下載量格式化為xx,xxx格式如:12,000
select format(money,2) as money from user; 把用戶金錢格式化為xx,xxx.xx格式,參數(shù)2為精確的小數(shù)點(diǎn)位數(shù)如:12,000.05


mysql length函數(shù)
計(jì)算某個(gè)字段值的長度
例:
select length(name) as length from user; 顯示出用戶名的長度
select * from table where length(aa) > 10 ; 查詢某字段長度大于10的記錄 php程序員站

mysql distinct函數(shù)
對(duì)某個(gè)字段去重復(fù),(在某些時(shí)候group by也可以做到)
例:
select distinct(area) from user; 對(duì)地區(qū)進(jìn)行去重復(fù)
select area,count(*) from user group by area; 對(duì)地區(qū)進(jìn)行聚合并統(tǒng)計(jì)出數(shù)量

?

mysql replace函數(shù)
查找某個(gè)字符串并進(jìn)行替換
例:
select replace(icon,"www.iteye.com","img.iteye.com") from software; 把icon中的www.iteye.com替換成替換成img.iteye.com顯示
update software set icon=replace(icon,"www.iteye.com","img.iteye.com") ; 把數(shù)據(jù)庫中icon的域名批量進(jìn)行查找替換?www.iteye.com

mysql in函數(shù)
可批量指定幾個(gè)值作為查詢條件
例:
select * from user where user_id in(1,2,3,4,5,100,200,333)
select * from user where user_name in("a","b","d")

mysql like函數(shù)
可對(duì)某個(gè)字段進(jìn)行模糊查詢,"%"號(hào)用于匹配任意字符
例:
select * from user where name like "%王%"; 查詢所有用戶名中帶"王"字符的用戶
select * from user where name like "%王";? 查詢所有用戶名第一個(gè)字符為"王"字的用戶

?

mysql is null函數(shù)
匹配某個(gè)字符為null值的記錄,注:null不代表空符串""
例:
select * from user where a is null ; 查詢a字段為null的用戶
select a.* from user as a left join add_user as b on a.user_id=b.user_id where b.user_id is null; 連表查詢附加表add_user中沒有附加用戶信息數(shù)據(jù)的用戶


mysql is not null函數(shù)
和is null用法一樣,匹配某個(gè)字符不為空的記錄

?

mysql MATCH ... AGAINST 全文匹配函數(shù)
mysql的全文匹配函數(shù),要使用此函數(shù)查詢的字符必須增加了全文索引,另外mysql不支持中文全文索引,所以國人在開發(fā)中估計(jì)很少用到此函數(shù)。
match中包含要進(jìn)行全文匹配的字段,多個(gè)字段用","號(hào)分割 against為匹配的字符串
例:
select * from software where match(title,body) against("php"); 全文匹配title和body字段中包含"php"的記錄
select * from software where match(title) against("php mysql"); 全文匹配title字段中包含"php mysql"的記錄。


文章來自:http://chenhaibo0806999.iteye.com/blog/1447824


好像我沒有找到將String 強(qiáng)制轉(zhuǎn)換成int 的,如果需要這樣的操作,那就只能用:該字段+0 ,如此便可OK了。


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Performing logical backups using mysqldump in MySQL Performing logical backups using mysqldump in MySQL Jul 06, 2025 am 02:55 AM

mysqldump is a common tool for performing logical backups of MySQL databases. It generates SQL files containing CREATE and INSERT statements to rebuild the database. 1. It does not back up the original file, but converts the database structure and content into portable SQL commands; 2. It is suitable for small databases or selective recovery, and is not suitable for fast recovery of TB-level data; 3. Common options include --single-transaction, --databases, --all-databases, --routines, etc.; 4. Use mysql command to import during recovery, and can turn off foreign key checks to improve speed; 5. It is recommended to test backup regularly, use compression, and automatic adjustment.

Implementing Transactions and Understanding ACID Properties in MySQL Implementing Transactions and Understanding ACID Properties in MySQL Jul 08, 2025 am 02:50 AM

MySQL supports transaction processing, and uses the InnoDB storage engine to ensure data consistency and integrity. 1. Transactions are a set of SQL operations, either all succeed or all fail to roll back; 2. ACID attributes include atomicity, consistency, isolation and persistence; 3. The statements that manually control transactions are STARTTRANSACTION, COMMIT and ROLLBACK; 4. The four isolation levels include read not committed, read submitted, repeatable read and serialization; 5. Use transactions correctly to avoid long-term operation, turn off automatic commits, and reasonably handle locks and exceptions. Through these mechanisms, MySQL can achieve high reliability and concurrent control.

Calculating Database and Table Sizes in MySQL Calculating Database and Table Sizes in MySQL Jul 06, 2025 am 02:41 AM

To view the size of the MySQL database and table, you can query the information_schema directly or use the command line tool. 1. Check the entire database size: Execute the SQL statement SELECTtable_schemaAS'Database',SUM(data_length index_length)/1024/1024AS'Size(MB)'FROMinformation_schema.tablesGROUPBYtable_schema; you can get the total size of all databases, or add WHERE conditions to limit the specific database; 2. Check the single table size: use SELECTta

Handling character sets and collations issues in MySQL Handling character sets and collations issues in MySQL Jul 08, 2025 am 02:51 AM

Character set and sorting rules issues are common when cross-platform migration or multi-person development, resulting in garbled code or inconsistent query. There are three core solutions: First, check and unify the character set of database, table, and fields to utf8mb4, view through SHOWCREATEDATABASE/TABLE, and modify it with ALTER statement; second, specify the utf8mb4 character set when the client connects, and set it in connection parameters or execute SETNAMES; third, select the sorting rules reasonably, and recommend using utf8mb4_unicode_ci to ensure the accuracy of comparison and sorting, and specify or modify it through ALTER when building the library and table.

Setting up asynchronous primary-replica replication in MySQL Setting up asynchronous primary-replica replication in MySQL Jul 06, 2025 am 02:52 AM

To set up asynchronous master-slave replication for MySQL, follow these steps: 1. Prepare the master server, enable binary logs and set a unique server-id, create a replication user and record the current log location; 2. Use mysqldump to back up the master library data and import it to the slave server; 3. Configure the server-id and relay-log of the slave server, use the CHANGEMASTER command to connect to the master library and start the replication thread; 4. Check for common problems, such as network, permissions, data consistency and self-increase conflicts, and monitor replication delays. Follow the steps above to ensure that the configuration is completed correctly.

Connecting to MySQL Database Using the Command Line Client Connecting to MySQL Database Using the Command Line Client Jul 07, 2025 am 01:50 AM

The most direct way to connect to MySQL database is to use the command line client. First enter the mysql-u username -p and enter the password correctly to enter the interactive interface; if you connect to the remote database, you need to add the -h parameter to specify the host address. Secondly, you can directly switch to a specific database or execute SQL files when logging in, such as mysql-u username-p database name or mysql-u username-p database name

Managing Character Sets and Collations in MySQL Managing Character Sets and Collations in MySQL Jul 07, 2025 am 01:41 AM

The setting of character sets and collation rules in MySQL is crucial, affecting data storage, query efficiency and consistency. First, the character set determines the storable character range, such as utf8mb4 supports Chinese and emojis; the sorting rules control the character comparison method, such as utf8mb4_unicode_ci is case-sensitive, and utf8mb4_bin is binary comparison. Secondly, the character set can be set at multiple levels of server, database, table, and column. It is recommended to use utf8mb4 and utf8mb4_unicode_ci in a unified manner to avoid conflicts. Furthermore, the garbled code problem is often caused by inconsistent character sets of connections, storage or program terminals, and needs to be checked layer by layer and set uniformly. In addition, character sets should be specified when exporting and importing to prevent conversion errors

Designing a Robust MySQL Database Backup Strategy Designing a Robust MySQL Database Backup Strategy Jul 08, 2025 am 02:45 AM

To design a reliable MySQL backup solution, 1. First, clarify RTO and RPO indicators, and determine the backup frequency and method based on the acceptable downtime and data loss range of the business; 2. Adopt a hybrid backup strategy, combining logical backup (such as mysqldump), physical backup (such as PerconaXtraBackup) and binary log (binlog), to achieve rapid recovery and minimum data loss; 3. Test the recovery process regularly to ensure the effectiveness of the backup and be familiar with the recovery operations; 4. Pay attention to storage security, including off-site storage, encryption protection, version retention policy and backup task monitoring.

See all articles