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自動增長爲2sql
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取出了年份,第二取出了月份和年份組合spa
INSERT IGNORE INTO tags (tag) VALUES ('good');
這個insert語句能夠執行屢次,不會報錯,重複的插入會被忽略blog
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一個月之前的全部記錄it
SET NAMES 'utf8';
請在鏈接開始後執行這個語句io
INSERT INTO yourtable (field1,field2,field3) SELECT newfield1,newfield2,'fixed value' FROM yourtable2
這個語句可以快速的幫助你們快速的添加一個表中的特定內容到另一個表中table