mongo與sql對比 來自網上

2021-10-21 14:37:21 字數 2569 閱讀 6311

在網路上收集資訊,如有問題,及時溝通

mongodb常用查詢語句

1、查詢所有記錄

db.userinfo.find();

相當於:select* from userinfo;

2、查詢去掉後的當前聚集集合中的某列的重複資料

db.userinfo.distinct(

"name");

會過濾掉 name 中的相同資料

相當於:select distict name from userinfo;

3、查詢 age = 22 的記錄

db.userinfo.find();

相當於: select * from userinfo where age = 22;

4、查詢 age > 22 的記錄

db.userinfo.find(})

;相當於:select * from userinfo where age >22;

5、查詢 age < 22 的記錄

db.userinfo.find(})

;相當於:select * from userinfo where age <22;

6、查詢 age >= 25 的記錄

db.userinfo.find(})

;相當於:select * from userinfo where age >= 25;

7、查詢 age <= 25 的記錄

db.userinfo.find(})

;8、查詢 age >= 23 並且 age <= 26 注意書寫格式

db.userinfo.find(})

;9、查詢 name 中包含 mongo 的資料 模糊查詢用於搜尋

db.userinfo.find();

//相當於%%

select * from userinfo where name like 『%mongo%』;

10、查詢 name 中以 mongo 開頭的

db.userinfo.find();

select * from userinfo where name like 『mongo%』;

11、查詢指定列 name、age 資料

db.userinfo.find(, )

;相當於:select name, age from userinfo;

當然 name 也可以用 true 或 false,當用 ture 的情況下河 name:1 效果一樣,如果用 false 就

是排除 name,顯示 name 以外的列資訊。

12、查詢指定列 name、age 資料, age > 25

db.userinfo.find(

}, )

;相當於:select name, age from userinfo where age >25;

13、按照年齡排序 1 公升序 -1 降序

公升序:db.userinfo.find(

).sort();

降序:db.userinfo.find(

).sort();

14、查詢 name = zhangsan, age = 22 的資料

db.userinfo.find();

相當於:select * from userinfo where name = 『zhangsan』 and age = 『22』;

15、查詢前 5 條資料

db.userinfo.find(

).limit(5)

;相當於:selecttop 5 * from userinfo;

16、查詢 10 條以後的資料

db.userinfo.find(

).skip(10)

;相當於:select * from userinfo where id not in

(selecttop 10 * from userinfo);

17、查詢在 5-10 之間的資料

db.userinfo.find(

).limit(10).skip(5)

;可用於分頁,limit 是 pagesize,skip 是第幾頁*pagesize

18、or 與 查詢

db.userinfo.find(, ]

});相當於:select * from userinfo where age = 22 or age = 25;

19、findone 查詢第一條資料

db.userinfo.findone();

相當於:selecttop 1 * from userinfo;

db.userinfo.find(

).limit(1)

;20、查詢某個結果集的記錄條數 統計數量

db.userinfo.find(

}).count();

相當於:select count(*) from userinfo where age >= 20;

如果要返回限制之後的記錄數量,要使用 count(true)或者 count(非 0)

db.users.find(

).skip(10).limit(5).count(true)

;

SQL與PLSQL的對比

1.sql99是什麼 1 是操作所有關係型資料庫的規則 2 是 語言 3 是一種結構化查詢語言 4 只需發出合法合理的命令,就有對應的結果顯示 2.sql的特點 1 互動性強,非過程化 2 資料庫操縱能力強,只需傳送命令,無需關注如何實現 3 多表操作時,自動導航簡單,例如 select emp.e...

儲存過程與SQL語句對比

優勢 1 提高效能 sql語句在建立過程時進行分析和編譯。儲存過程是預編譯的,在首次執行乙個儲存過程時,查詢優化器對其進行分析 優化,並給出最終被存在系統表中的儲存計畫,這樣,在執行過程時便可節省此開銷。2 降低網路開銷 儲存過程呼叫時只需用提供儲存過程名和必要的引數資訊,從而可降低網路的流量。3 ...

儲存過程與SQL的對比?

優勢 1 提高效能 sql語句在建立過程時進行分析和編譯。儲存過程是預編譯的,在首次執行乙個儲存過程時,查詢優化器對其進行分析 優化,並給出最終被存在系統表中的儲存計畫,這樣,在執行過程時便可節省此開銷。2 降低網路開銷 儲存過程呼叫時只需用提供儲存過程名和必要的引數資訊,從而可降低網路的流量。3 ...