Nội dung của bài Truy vấn dữ liệu nhằm giúp các em biết khái niệm và vai trò của truy vấn (mẫu hỏi), biết vận dụng một số hàm và phép toán tạo ra các biểu thức số học, biểu thức điều kiện và biểu thức logic để xây dựng mẫu hỏi, biết các bước chính để tạo ra một truy vấn, biết sử dụng hai chế độ làm việc với mẫu hỏi (chế độ thiết kế và chế độ trang dữ liệu). Mời các em cùng theo dõi nội dung của bài học dưới đây.

### 1. Các khái niệm

#### a. Mẫu hỏi

• Trong CSDL, chứa các thông tin về đối tượng ta đang quản lí. Dựa vào nhu cầu thực tế công việc, người lập trình phải biết cách lấy thông tin ra theo yêu cầu nào đó
• Access cung cấp công cụ để tự động hóa việc trả lời các câu hỏi do chính người lập trình tạo ra
• Mẫu hỏi thường được sử dụng để:
• Sắp xếp các bản ghi
• Chọn các bản ghi thỏa mãn các điều kiện cho trước
• Chọn các trường để hiển thị
• Thực hiện tính toán trên dữ liệu lấy ra
• Tổng hợp và hiển thị thông tin từ nhiều bảng hoặc mẫu hỏi khác
• Có 2 chế độ làm việc: Chế độ thiết kế và trang dữ liệu

#### b. Biểu thức trong Access

##### b.1. Các phép toán thường dùng
• Để thực hiện các tính toán và kiểm tra các điều kiện, ta phải biết cách viết các biểu thức đó
• Các biểu thức trong Access là: biểu thức số học, biểu thức điều kiện và biểu thức lôgic
• Các phép toán thường dùng:
• Phép toán số học: +,-,*,/
• Phép toán so sánh: <, >, <=,>=,=,<> (không bằng)
• Phép toán Lôgic: AND (và), OR (hoặc), NOT (phủ định).
• Phép toán ghép chuỗi: &
• ##### Tên trường: (đóng vai trò các biến) được ghi trong dấu ngoặc vuông. Ví dụ: [TOAN], [LUONG]
• Hằng số: Ví dụ: 0.1; 1000000,…
• Hằng văn bản: được viết trong dấu nháy kép. Ví dụ: “Nam”, “Nữ”,…
• Biểu thức số học: Mô tả các trường tính toán trong mẫu hỏi. Ví dụ:  MAT_DO: [SO_DAN]/[DIEN_TICH]

#### d. Các hàm số trong Access:

• Hàm số trong Access dùng để tính tóan các dữ liệu trên trường chỉ định.  Một số hàm thông dụng để tính tóan trên trường có dữ liệu số như sau:
• SUM: Tính tổng giá trị số trên trường chỉ định.
• AVG: Tính giá trị trung bình các giá trị số trên trường chỉ định
• MIN: Tìm giá trị nhỏ nhất của các số nằm trên trường chỉ định
• MAX: Tìm giá trị lớn nhất của các số nằm trên trường chỉ định
• COUNT: Đêm các ô khác rỗng nằm trên trường chỉ định
• ROUND(a,n): làm tròn biểu thức số: a, đến n số lẻ. Ví dụ về cách sử dụng hàm số ROUND((2*[TOAN]+2*[VAN]+[TIN_HOC])/5,1) là làm tròn biểu thức trong ngoặc đến 1 số lẻ

### 2. Tạo mẫu hỏi

• Để làm việc với mẫu hỏi, chọn Queries trong bảng chọn đối tượng.
• Có thể tạo mẫu hỏi mới bằng cách dùng thuật sĩ hoặc tự thiết kế.
• Các bước chính để tạo một mẫu hỏi bao gồm:
• Chọn dữ liệu nguồn (các bảng và mẫu hỏi khác) cho mẫu hỏi;
• Chọn các trường từ dữ liệu nguồn để đưa vào mẫu hỏi;
• Khai báo các điều kiện để lọc các bản ghi cần đưa vào mẫu hỏi;
• Chọn các trường dùng để sắp xếp các bản ghi trong mẫu hỏi;
• Tạo các trường tính toán từ các trường đã có;
• Đặt điều kiện gộp nhóm.

Chú ý:

• Không nhất thiết phải thực hiện tất cả các bước này.
• Có hai chế độ thường dùng để làm việc với mẫu hỏi: chế độ thiết kế và chế độ trang dữ liệu.

Trong chế độ thiết kế, ta có thể thiết kế mới hoặc xem hay sửa đổi thiết kế cũ của mẫu hỏi. Trên hình 1dưới đây là thanh công cụ thiết kế mẫu hỏi.

Hình 1. Thanh công cụ thiết kế mẫu hỏi

Để thiết kế mẫu hỏi mới, thực hiện một trong hai cách sau:

• Cách 1: Nháy đúp vào Create query by using wizard.
• Cách 2: Nháy đúp vào Create query in Design view.

Hình 2. Mẫu hỏi ở chế độ thiết kế

Để xem hay sửa đổi thiết kế mẫu hỏi, thực hiện:

• Bước 1. Chọn mẫu hỏi cần xem hoặc sửa.
• Bước 2. Nháy nút .

Cửa sổ mẫu hỏi ở chế độ thiết kế gồm hai phần:

• Phần trên (nguồn dữ liệu) hiển thị cấu trúc các bảng (và các mẫu hỏi khác) có chứa các trường được chọn để dùng trong mẫu hỏi này.
• Phần dưới là lưới QBE (Query By Example – mẫu hỏi theo ví dụ), nơi mô tả mẫu hỏi. Mỗi cột thể hiện một trường sẽ được sử dụng trong mẫu hỏi. Nội dung của từng hàng gồm có:
• Field: Khai báo tên các trường được chọn. Đó là các trường sẽ có mặt trong mẫu hỏi hoặc các trường dùng để lọc, sắp xếp, kiểm tra giá trị…
• Table: Tên bảng chứa trường tương ứng.
• Sort: Xác định (các) trường cần sắp xếp.
• Show: Xác định (các) trường xuất hiện trong mẫu hỏi.
• Criteria: Mô tả điều kiện để chọn các bản ghi đưa vào mẫu hỏi. Các điều kiện được viết dưới dạng biểu thức lôgic.

Khi đang ở chế độ thiết kế mẫu hỏi, ta có thể thực hiện mẫu hỏi để xem kết quả bằng cách nháy nút  hoặc nút  hoặc chọn lệnh View $$\rightarrow$$ Datasheet View.

#### 362 BÌNH LUẬN

1. each time i used to read smaller posts that as well clear their motive, and that is also happening with this article which I am reading here.

2. I’m amazed, I must say. Rarely do I encounter a blog that’s
both equally educative and amusing, and let me tell
you, you’ve hit the nail on the head. The problem is an issue that not enough folks are speaking intelligently about.
I’m very happy I stumbled across this in my search
for something concerning this.

3. Howdy! Would you mind if I share your blog with my
zynga group? There’s a lot of people that
Thank you

4. I take pleasure in, cause I discovered exactly what I was taking a look for.

You have endded my 4 day lengthy hunt! God Bless you man. Have a nice day.
Bye

5. I’m really enjoying the theme/design of your web site. Do you ever run into aany web browsaer compatibilitty issues?

A couple of my boog visitors have complained about my blog not working correctly in Exploder buut looks great in Safari.

Do yoou have any suggestons to help fix this problem?

6. I’m not sure exactly why but this weblog is loading incredibly slow for me.

Is anyone else having this problem or is it a problem on my end?
I’ll check back later and see if the problem still exists.

7. This is really interesting, You are a very skilled blogger.
I have joined your feed and look forward to seeking more of your excellent post.
Also, I’ve shared your site in my social networks!

8. Heya superb website! Does running a blog such as this take a massive amount work?
I’ve absolutely no understanding of coding but I had been hoping to start my own blog in the near future.
Anyway, should you have any suggestions or techniques for new blog
Kudos!

9. I think the admin of this web page is genuinely working
hard for his website, as here every data is quality based data.

10. It’s in point of fact a great and useful piece of information. I’m happy that you simply shared this helpful info with us.

Please keep us informed like this. Thanks for sharing.

11. Generally I do not read post on blogs, but I would like to
say that this write-up very pressured me to check
out and do so! Your writing style has been amazed me.

Thank you, quite great article.

12. I am curious to find out what blog system you’re utilizing?
I’m having some minor security problems with my latest blog and I’d
like to find something more risk-free. Do you have any solutions?

13. I’m really enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more
often. Did you hire out a designer to create your theme?
Outstanding work!

14. It is really a nice and useful piece of information. I am happy that you
simply shared this helpful information with us. Please stay us up to date like this.
Thank you for sharing.

15. Greetings! This is my 1st comment here so I just wanted to give a quick shout out and say I genuinely enjoy
blogs/websites/forums that deal with the same subjects? Appreciate it!

16. Attractive section of content. I just stumbled upon your blog and in accession capital to assert that I acquire actually enjoyed account your blog posts.
Any way I’ll be subscribing to your feeds and even I achievement you access
consistently quickly.

17. An intriguing discussion is worth comment. There’s no doubt that that you ought to write more about this subject matter, it might not be a taboo matter
but generally people do not discuss these subjects.
To the next! Kind regards!!

18. I’m not sure exactly why but this website is loading extremely slow for me.
Is anyone else having this issue or is it a problem on my end?
I’ll check back later and see if the problem still exists.

19. Hi, I think your blog might be having browser compatibility issues.

when opening in Internet Explorer, it has some overlapping.
I just wanted to give you a quick heads up! Other then that, very good blog!

20. Do you have a spam problem on this website; I also am a blogger, and I was curious about your situation; we have developed some nice methods and we are looking to trade strategies with other folks, be
sure to shoot me an email if interested.

21. My partner and I stumbled over here by a different
page and thought I may as well check things out. I like what I see so i am just
following you. Look forward to going over your web page yet again.

22. Have you ever considered writing an e-book or guest
authoring on other websites? I have a blog centered on the same topics you discuss and would really like to have you
If you are even remotely interested, feel free to
shoot me an e mail.

23. Hello would you mind letting me know which web host you’re utilizing?
Can you recommend a good internet hosting provider at a fair
price? Thanks a lot, I appreciate it!

24. It’s hard to come by knowledgeable people on this topic, however, you seem
like you know what you’re talking about! Thanks

25. I have been surfing online more than 3 hours today, yet I never found any
interesting article like yours. It’s pretty worth enough for me.
In my opinion, if all website owners and bloggers made good
content as you did, the internet will be a lot more useful
than ever before.

26. With havin so much written content do you ever run into any issues of plagorism or copyright violation? My
website has a lot of exclusive content I’ve either authored myself or outsourced but it appears a lot of it is popping it
up all over the web without my authorization. Do you know any techniques to help stop content from
being stolen? I’d truly appreciate it.

27. of course like your website but you need to test the spelling on several of
your posts. Several of them are rife with spelling
problems and I to find it very bothersome to tell the reality however I’ll surely come
back again.

28. I just like the helpful information you supply for your articles.
I will bookmark your blog and check once more here
regularly. I’m moderately certain I will be informed lots of new
stuff proper right here! Good luck for the following!

29. A person essentially assist to make significantly posts I’d state.
This is the very first time I frequented your
web page and up to now? I amazed with the research
you made to create this actual post extraordinary. Magnificent process!

30. Write more, thats all I have to say. Literally, it seems as
though you relied on the video to make your point.
You clearly know what youre talking about, why throw away your intelligence on just
posting videos to your blog when you could be giving us something enlightening to read?

31. I was recommended this web site via my cousin. I’m not certain whether or not this
publish is written via him as no one else recognise such exact about my problem.
You’re amazing! Thank you!

32. I got this web site from my friend who informed me about this web site and now this time I am visiting this web
site and reading very informative articles here.

33. tsoQQm Whoa! This blog looks just like my old one! It as on a entirely different topic but it has pretty much the same layout and design. Great choice of colors!

34. If some one desires to be updated with most up-to-date technologies therefore he must be
go to see this web page and be up to date everyday.

35. Wow, marvelous blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your web site is fantastic, let alone the content!

36. Wonderful blog! I found it while surfing around on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I ave been trying for a while but I never seem to get there! Many thanks

37. My brother suggested I might like this web site. He was totally right. This post actually made my day. You cann at imagine simply how much time I had spent for this information! Thanks!

38. Wow, incredible weblog structure! How long have you been running a blog for? you made running a blog look easy. The overall look of your web site is wonderful, let alone the content material!

39. Right now it seems like Drupal could be the preferred blogging platform available at the moment. (from what I ave read) Is the fact that what you are using in your weblog?

40. I have to thank you for the efforts you have put in writing this website. I’m hoping to see the same high-grade content from you later on as well. In fact, your creative writing abilities has encouraged me to get my very own site now 😉

41. This is the perfect site for anyone who would like to find out about this topic. You understand a whole lot its almost tough to argue with you (not that I personally will need toÖHaHa). You definitely put a brand new spin on a subject that’s been discussed for a long time. Great stuff, just excellent!

42. A motivating discussion is definitely worth comment. I think that you ought to publish more on this issue, it may not be a taboo matter but typically people do not discuss such subjects. To the next! All the best!!

43. This is a great tip particularly to those new to the blogosphere. Short but very precise informationÖ Thank you for sharing this one. A must read article!

44. You are so interesting! I do not think I’ve read through something like that before. So nice to discover somebody with a few unique thoughts on this issue. Seriously.. thank you for starting this up. This website is something that is required on the web, someone with some originality!

45. Wow! This can be one particular of the most beneficial blogs We ave ever arrive across on this subject. Basically Great. I am also an expert in this topic therefore I can understand your hard work.

46. Wow! This could be one particular of the most useful blogs We ave ever arrive across on this subject. Basically Great. I am also an expert in this topic so I can understand your effort.

47. I simply could not leave your website before suggesting that I actually loved the usual information an individual supply in your guests? Is gonna be back regularly in order to inspect new posts

48. Wow that was strange. I just wrote an really long comment but after I clicked submit my
comment didn’t show up. Grrrr… well I’m not writing
all that over again. Anyways, just wanted to say fantastic blog!

49. IaаАабТТаЂааАабТТаБТve learn a few excellent stuff here. Definitely price bookmarking for revisiting. I wonder how so much attempt you put to make this kind of great informative web site.

50. You could definitely see your expertise in the work you write. The world hopes for more passionate writers like you who are not afraid to say how they believe. Always go after your heart.

51. The political landscape is ripe for picking In this current political climate, we feel that there as simply no hope left anymore.

52. Wow! This can be one particular of the most helpful blogs We ave ever arrive across on this subject. Basically Great. I am also a specialist in this topic so I can understand your effort.

53. Wow! This could be one particular of the most helpful blogs We ave ever arrive across on this subject. Basically Excellent. I am also an expert in this topic therefore I can understand your effort.

54. You could definitely see your skills within the work you write. The world hopes for more passionate writers like you who are not afraid to say how they believe. At all times go after your heart.

55. This content has a lot of great information that is apparently intended to make you think. There are excellent points made here and I agree on many. I like the way this content is written.

56. Very nice article and straight to the point. I don at know if this is in fact the best place to ask but do you people have any thoughts on where to employ some professional writers? Thx

57. Every Day our hacker group Will update the store with Fresh Cards, Paypal verified balance, Accounts store ( ebay,amazon,Bank login,fullz info dob ssn…)

58. I truly appreciate this post. I ave been looking all over for this! Thank goodness I found it on Bing. You have made my day! Thank you again.

59. I have learn a few excellent stuff here. Definitely value bookmarking for revisiting.
I surprise how much attempt you put to make any such excellent
informative site.

60. Pacientes diabéticos: No se requiere ajuste de la dosis en pacientes diabéticos. En definitiva, se trata de cuidar su estilo de vida, como el año pasado alumbró un estudio de la Universidad de Adelaida (Australia), que con este sorprendente titular llamó poderosamente la atención: “La disfunción eréctil puede curarse sin medicación”. Una lesión en la columna vertebral, la próstata, la pelvis o la vejiga puede ocasionar la DE lesionanado los nervios, arterias, músculos lisos.

61. Hello everyone, it’s my first go to see at this web page, and post is genuinely fruitful in favor of me,
keep up posting such articles.

62. Wow! This can be one particular of the most useful blogs We ave ever arrive across on this subject. Actually Magnificent. I am also a specialist in this topic so I can understand your effort.

63. Way cool! Some extremely valid points! I appreciate you writing this post and the rest of the site is extremely good.

64. That is a good tip especially to those new to the blogosphere. Brief but very precise info Thanks for sharing this one. A must read article!

65. Wow, wonderful blog structure! How lengthy have you ever been running a blog for? you made blogging glance easy. The overall glance of your site is wonderful, let alone the content material!

66. Just want to say your article is as amazing. The clarity in your post is just spectacular and i could assume you’re an expert on this subject.
post. Thanks a million and please keep up the enjoyable work.

67. Hi, I do think this is an excellent blog. I stumbledupon it 😉 I am going to come back yet again since i have saved as a favorite
it. Money and freedom is the greatest way to change,
may you be rich and continue to guide others.

68. Please let me know if you’re looking for a article author for your site.
You have some really good posts and I think I would
be a good asset. If you ever want to take some of the load off, I’d absolutely love
Please shoot me an email if interested. Thanks!

69. I simply could not depart your website prior to suggesting that I extremely enjoyed the standard info an individual supply on your guests? Is gonna be back frequently in order to inspect new posts

70. You can certainly see your expertise within the article you write.
The world hopes for even more passionate writers like you who are not
afraid to say how they believe. All the time go after your heart.

71. Website We Recommend You made some fine points there. I did a search on the subject and found nearly all folks will consent with your blog.

72. Looking around I like to surf around the online world, often I will just go to Stumble Upon and follow thru

73. This very blog is no doubt entertaining and also factual. I have discovered a bunch of handy tips out of this amazing blog. I ad love to come back every once in a while. Thanks a bunch!

74. I used to be suggested this web site via my cousin.
I am not sure whether or not this submit is written through him as nobody else recognise such distinctive approximately my difficulty.

You are amazing! Thank you!

75. Wow! This can be one particular of the most useful blogs We have ever arrive across on this subject. Actually Great. I am also an expert in this topic therefore I can understand your effort.

76. I’аll right away grasp your rss feed as I can not to find your email subscription link or newsletter service. Do you have any? Kindly permit me recognize so that I may subscribe. Thanks.

77. That is a great tip especially to those fresh to the blogosphere. Simple but very precise information Many thanks for sharing this one. A must read article!

78. This particular blog is definitely cool and also factual. I have picked a bunch of helpful things out of this blog. I ad love to return again and again. Thanks a bunch!

79. We appreciate, result in I ran across what exactly I had been seeking. You could have wrapped up my own Some evening extended quest! Our god Bless you man. Use a fantastic time. Ok bye

80. It as onerous to find knowledgeable folks on this subject, but you sound like you realize what you are talking about! Thanks

81. Very nice post. I just stumbled upon your blog and wanted to say that I have really enjoyed surfing around your blog posts. After all I all be subscribing to your feed and I hope you write again soon!

82. My spouse and I stumbled over here by a different web page and thought I should check things out. I like what I see so now i am following you. Look forward to finding out about your web page again.

83. What as Happening i am new to this, I stumbled upon this I ave found It positively useful and it has helped me out loads. I hope to contribute & help other users like its helped me. Good job.

84. Well I sincerely liked reading it. This tip provided by you is very effective for proper planning.

85. Nice blog here! Also your website rather a lot up very fast! What host are you the usage of? Can I am getting your associate link in your host? I want my website loaded up as fast as yours lol

86. This particular blog is really interesting additionally amusing. I have discovered a bunch of helpful advices out of this blog. I ad love to come back again soon. Thanks!

87. Wow! This could be one particular of the most useful blogs We have ever arrive across on this subject. Actually Magnificent. I am also a specialist in this topic so I can understand your effort.

88. This is a really good tip especially to those fresh to the blogosphere. Short but very precise information Thanks for sharing this one. A must read post!

89. I simply could not leave your website before suggesting that I extremely enjoyed the standard info an individual supply to your guests? Is going to be again ceaselessly in order to inspect new posts.