- SELECT id,title,
- (CASE date WHEN '0000-00-00' THEN '' ELSE date END) AS date
- FROM your_table
- SELECT id,title,
- (CASE status WHEN 0 THEN 'open' WHEN 1 THEN 'close' ELSE 'standby' END) AS status
- FROM your_table
- SELECT email, COUNT(email) AS q
- FROM emails_table GROUP BY email HAVING q > 1
- ORDER BY q DESC
- SELECT * FROM your_table ORDER BY RAND()
- UPDATE your_table
- SET name=REPLACE(name, 'gbin1.com', 'gbtags.com')
- WHERE name LIKE '%John%';
- ALTER TABLE your_table AUTO_INCREMENT = 2
下一次你插入数据,那么id自动增加为2
- set @N = 0;
- SELECT @N := @N +1 AS number, name, surname FROM gbtags_users;
- SELECT CONCAT(name,' ',surname) AS complete_name FROM users
- SELECT id,title, YEAR(date_field) FROM your_table
- SELECT id,title,
- CONCAT(MONTH(date_field),'/',YEAR(date_field)) as new_date
- FROM your_table
上面语句,第一个select取出了年份,第二取出了月份和年份组合
- INSERT IGNORE INTO tags (tag) VALUES ('good');
这个insert语句可以执行多次,不会报错,重复的插入会被忽略
- select * from articles where MATCH(content_column) AGAINST ('music')
你需要首先添加全文搜索索引到指定的列(content_column)。注意如果你表里已经有数据的话,不会创建索引,所以你需要使用一个空的表来执行这个语句
- SELECT user, count(*) AS logins
- FROM stat_log
- WHERE action='LOGIN' AND dt_when >= DATE_ADD(CURDATE(), INTERVAL -1 MONTH)
- GROUP BY user
这个语句能够让你查询字段dt_when一个月以前的所有记录
- SET NAMES 'utf8';
请在连接开始后执行这个语句
- INSERT INTO yourtable (field1,field2,field3)
- SELECT newfield1,newfield2,'fixed value'
- FROM yourtable2
这个语句能够快速的帮助大家快速的添加一个表中的特定内容到另外一个表中。