自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

一個(gè)SQLite數(shù)據(jù)庫查詢數(shù)據(jù)的代碼實(shí)例

數(shù)據(jù)庫 其他數(shù)據(jù)庫
本文主要介紹了SQLite數(shù)據(jù)庫查詢數(shù)據(jù)的一個(gè)實(shí)例,通過這個(gè)實(shí)例讓我們來更進(jìn)一步地了解SQLite數(shù)據(jù)庫的查詢。

我們知道,在SQL Server數(shù)據(jù)庫中查詢數(shù)據(jù)時(shí)需要用到SELECT……FROM語句結(jié)合WHERE條件來實(shí)現(xiàn)的,其實(shí)SQLite數(shù)據(jù)庫查詢數(shù)據(jù)的方式也是這樣的,本文通過一個(gè)實(shí)例來介紹這一過程,希望能給大家?guī)硎斋@。

首先將下面的SQL 語句保存到 data.sql 文件中(為了以后的練習(xí)使用):

 

  1. BEGIN TRANSACTION;  
  2.  
  3. CREATE TABLE Cars(Id integer PRIMARY KEY, Name text, Cost integer);  
  4.  
  5. INSERT INTO Cars VALUES(1,'Audi',52642);  
  6.  
  7. INSERT INTO Cars VALUES(2,'Mercedes',57127);  
  8.  
  9. INSERT INTO Cars VALUES(3,'Skoda',9000);  
  10.  
  11. INSERT INTO Cars VALUES(4,'Volvo',29000);  
  12.  
  13. INSERT INTO Cars VALUES(5,'Bentley',350000);  
  14.  
  15. INSERT INTO Cars VALUES(6,'Citroen',21000);  
  16.  
  17. INSERT INTO Cars VALUES(7,'Hummer',41400);  
  18.  
  19. INSERT INTO Cars VALUES(8,'Volkswagen',21600);  
  20.  
  21. COMMIT;  
  22.  
  23. BEGIN TRANSACTION;  
  24.  
  25. CREATE TABLE Orders(Id integer PRIMARY KEY, OrderPrice integer CHECK(OrderPrice>0),   
  26.  
  27. Customer text);  
  28.  
  29. INSERT INTO Orders(OrderPrice, Customer) VALUES(1200, "Williamson");  
  30.  
  31. INSERT INTO Orders(OrderPrice, Customer) VALUES(200, "Robertson");  
  32.  
  33. INSERT INTO Orders(OrderPrice, Customer) VALUES(40, "Robertson");  
  34.  
  35. INSERT INTO Orders(OrderPrice, Customer) VALUES(1640, "Smith");  
  36.  
  37. INSERT INTO Orders(OrderPrice, Customer) VALUES(100, "Robertson");  
  38.  
  39. INSERT INTO Orders(OrderPrice, Customer) VALUES(50, "Williamson");  
  40.  
  41. INSERT INTO Orders(OrderPrice, Customer) VALUES(150, "Smith");  
  42.  
  43. INSERT INTO Orders(OrderPrice, Customer) VALUES(250, "Smith");  
  44.  
  45. INSERT INTO Orders(OrderPrice, Customer) VALUES(840, "Brown");  
  46.  
  47. INSERT INTO Orders(OrderPrice, Customer) VALUES(440, "Black");  
  48.  
  49. INSERT INTO Orders(OrderPrice, Customer) VALUES(20, "Brown");  
  50.  
  51. COMMIT; 

 

然后在在終端執(zhí)行命令 .read data.sql,將數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫中:

 

  1. sqlite> 
  2.  
  3. sqlite> .tables  
  4.  
  5. Friends  
  6.  
  7. sqlite> .read data.sql  
  8.  
  9. sqlite> .tables  
  10.  
  11. Cars Orders Teachers  
  12.  
  13. sqlite> 

 

可以看到,Cars 表和 Orders 表已經(jīng)導(dǎo)入到數(shù)據(jù)庫中,現(xiàn)在可以查詢了:

 

  1. sqlite> 
  2.  
  3. sqlite> SELECT * FROM Cars;  
  4.  
  5. Id Name Cost  
  6.  
  7. ---- --------------- ---------------  
  8.  
  9. 1 Audi 52642  
  10.  
  11. 2 Mercedes 57127  
  12.  
  13. 3 Skoda 9000  
  14.  
  15. 4 Volvo 29000  
  16.  
  17. 5 Bentley 350000  
  18.  
  19. 6 Citroen 21000  
  20.  
  21. 7 Hummer 41400  
  22.  
  23. 8 Volkswagen 21600  
  24.  
  25. sqlite> SELECT * FROM Orders;  
  26.  
  27. Id OrderPrice Customer  
  28.  
  29. ---- --------------- ---------------  
  30.  
  31. 1 1200 Williamson  
  32.  
  33. 2 200 Robertson  
  34.  
  35. 3 40 Robertson  
  36.  
  37. 4 1640 Smith  
  38.  
  39. 5 100 Robertson  
  40.  
  41. 6 50 Williamson  
  42.  
  43. 7 150 Smith  
  44.  
  45. 8 250 Smith  
  46.  
  47. 9 840 Brown  
  48.  
  49. 10 440 Black  
  50.  
  51. 11 20 Brown  
  52.  
  53. sqlite> 

 

 關(guān)于SQLite數(shù)據(jù)庫查找數(shù)據(jù)的知識(shí)就介紹到這里,我們還會(huì)在以后的文章里繼續(xù)介紹,謝謝各位一直以來的支持!

【編輯推薦】

  1. SQLite 基本控制臺(tái)命令簡(jiǎn)介
  2. 使用SQLite擴(kuò)展函數(shù)來定義自己的函數(shù)
  3. 在SQLite中統(tǒng)計(jì)本周本月數(shù)據(jù)的代碼實(shí)例
  4. 一個(gè)SQLite數(shù)據(jù)庫插入數(shù)據(jù)的經(jīng)典代碼實(shí)例
  5. 一個(gè)SQLite數(shù)據(jù)庫修改和刪除數(shù)據(jù)的代碼實(shí)例
責(zé)任編輯:趙鵬 來源: 博客園
相關(guān)推薦

2011-07-20 12:55:17

SQLite數(shù)據(jù)庫插入數(shù)據(jù)

2011-07-20 14:32:59

SQLite數(shù)據(jù)庫LIKE查詢IN集合查詢

2011-07-20 14:57:47

SQLite數(shù)據(jù)庫ORDER BYGROUP BY

2011-07-20 13:18:01

SQLite數(shù)據(jù)庫修改和刪除數(shù)據(jù)

2012-05-11 10:24:05

SQL數(shù)據(jù)庫SQLitl

2011-07-05 14:46:34

2011-07-05 10:16:16

Qt 數(shù)據(jù)庫 SQLite

2011-07-20 14:06:11

SQLite數(shù)據(jù)庫限制返回行數(shù)

2025-04-17 04:00:00

SQLite-WebSQLite數(shù)據(jù)庫

2011-07-21 16:28:20

MySQL數(shù)據(jù)庫帶游標(biāo)的存儲(chǔ)過程

2011-07-18 10:45:55

C#SQL Server數(shù)

2011-07-21 17:29:42

iPhone Sqlite 數(shù)據(jù)庫

2020-08-26 14:45:34

SQL數(shù)據(jù)庫數(shù)次

2011-07-26 18:11:56

iPhone Sqlite 數(shù)據(jù)庫

2009-06-22 13:50:00

java連接mysql

2011-03-03 13:13:51

DelphiSQLite加密

2011-04-06 11:34:52

SQL Server數(shù)查詢優(yōu)化

2024-03-07 13:02:57

PythonSQLite數(shù)據(jù)庫

2011-07-19 09:46:00

Oracle數(shù)據(jù)庫遞歸查詢

2011-07-20 17:02:51

Oracle數(shù)據(jù)庫
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)