select id, title, 'haha' mark from course;
select * from (
select * from relation
) temp left join audio audio on audio.id = temp.audio_id
order by temp.id desc
批量更新條件查詢出來的資料:
update audio set is_delete = 1
where id in (select * from (select id from audio order by create_time desc limit 0,10) temp)
substring(column_name,n) // 擷取某一字段從第n個字元開始到結尾的字串;
substring(column_name,m,n) // 擷取某一字段從第m個到n個字元的字串;
update table set column = concat(column, 'hahaha') // 把column中的資料後面加上'hahaha';
concat 起到連線字串的作用,不過如果有乙個為null,那麼結果也為null;
concat_ws(separator, str1, str2, column1, column2...) // 起到用指定分隔符分隔字串/column的功能;
group_concat( [distinct] 要連線的字段 [order by 排序字段 asc/desc] [separator '分隔符'] )
group_concat可以把同一列資料查詢出為一行,並可以指定分隔符和排序,去重;
如果希望對整個查詢出來的結果進行統一排序,那麼可以不使用括號,只需要給後面的sql語句新增排序
select create_time, update_time from c2_course
union
select create_time, update_time from c2_lesson order by create_time;
如果使用union去結合兩個sql語句查詢出來的資料,如果兩個sql語句需要分別進行排序,那麼必須使用括號
(select * from table1 where mem_id = 111725 order by lesson_id)
union
(select * from table1 where mem_id = 23507 order by lesson_id);
// 這種方式是不管用的,union語句中的order by 是不生效的,需要使用如下方式:
select * from (select * from table1 where mem_id = 111725 order by lesson_id) a
union
select * from (select * from table1 where mem_id = 23507 order by lesson_id) b;
資料庫隨筆
目前軟體開發行業中,無論是移動端開發還是後端開發,基本上都會碰到資料庫的開發,這裡就談談筆者對於資料庫的感想 在移動端亦或是後端開發中,很多時候,我們會感覺到無論是 orm 還是其他方案,都會存在著一些缺點,其實這 於資料庫本身和開發語言本身的衝突,現代化的語言基本上都是物件導向開發,物件導向是從軟...
mysql資料庫查詢作業 mysql資料庫查詢練習
建立四張資料表 學生表student 學號,姓名,性別,出生年月日,所在班級 課程表course 課程號,課程名,教師編號 成績表score 學號,課程號,成績 教師表teacher 教師編號,教師名,教師性別,出生年月日,職稱,所在部門 新增資訊 學生表 insert into student v...
mysql資料庫查詢
這一段時間在實習的公司裡和別人共同開發乙個新功能,我主要偏資料庫操作!其中有乙個是對資料的校驗,而這些資料在資料庫裡是以樹的形式存在!沒有問別人之前我是打算以迴圈的方式來做,週日花了整整一下午把資料表研究了一番發現不是我想象的那麼簡單,我先把這個要求簡單的描述一下 首先是資料表裡的資料,欄位太多,我...