Mysql语句与应用
生活随笔
收集整理的這篇文章主要介紹了
Mysql语句与应用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
1。正則表達式
搜索多個關鍵詞,“或”, 等同 %上海% | %內蒙古%
SELECT?*?FROM?analysis_result?WHERE?result?REGEXP?'上海|內蒙古'?LIMIT?1;"且"
SELECT?*?FROM?analysis_result?WHERE?id?=?1?AND?result?REGEXP?'上海'?AND?result?REGEXP?'云南'?LIMIT?1; SELECT?*?FROM?analysis_result?WHERE?id?=?1?AND?result?LIKE?'%上海%'?AND?result?LIKE?'%云南%'?LIMIT?1;2.替換字符串
將"3G"替換成"MOBILE"
UPDATE?analysis_result?SET?result=replace(result,'3G','MOBILE')?WHERE?result_type?=?'PCNUM';3.betweeen and 與 >= ,決不能等同于 in
select?count(1)?from?default.user?where?univname?REGEXP?'上海'?and?univyear?between?2011?and?2013;select?count(1)?from?default.user?where?univname?REGEXP?'上海'?and?univyear?>=?2011?and??univyear?<=?2013; 不同于下面 select?count(1)?from?default.user?where?univname?REGEXP?'上海'?and?univyear?in?(2010,?2013);4.Group by 問題:Expression Not In Group By Key
select?a.collegename,?a.allcount?from?(select?collegename,?count(id)?as?allcount?from?default.user?where?collegename?!=?'\N'?group?by?collegename)?a?sort?by?a.allcount?DESC5.數據顯示 \N 的值,需要用 = '\\N' 去查詢,非的時候就用 != '\N'
INSERT?OVERWRITE?LOCAL?DIRECTORY??'/tmp/result.txt'?select?id,name?from?t_test; hive?-e?"select?count(id),?friendcount?from?default.user?where?id?>?0?and?birthday?!=?'\\N'?group?by?friendcount"??>?friendcount.txt hive?-e?"select?*?from?default.user?where?id?>?0?and?birthday?!=?'\\N'?group?by?friendcount?limit?10000"?>?user.txt需要特別指出的是,在篩選某些時間字段的時候,\N仍會被篩選進來
如下面會把 \N曬進來
select?*?from?user?where?regtime?>?'2014-01-01'?limit?10所以應該
select?*?from?user?where?regtime?!=?'\\N'?and?regtime?>?'2014-01-01'?limit?10;6.分組后排序
select?a.univname,?a.allcount?from?(select?univname,?count(id)?as?allcount?from?default.user?where?univname?!=?'\N'?group?by?univname)?a?sort?by?a.allcount?DESC轉載于:https://my.oschina.net/kingdelee/blog/309513
總結
以上是生活随笔為你收集整理的Mysql语句与应用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java对数组的操作(二)——集合与数组
- 下一篇: 局域网中设备的管理之StackClust