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: &
b.2. Các toán hạng trong tất cả các biểu thức
  • 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. 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.

  2. Howdy! Would you mind if I share your blog with my
    zynga group? There’s a lot of people that
    I think would really appreciate your content. Please let me know.
    Thank you

  3. 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

  4. 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?

  5. 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.

  6. 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!

  7. 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
    owners please share. I understand this is off topic however I simply had to ask.
    Kudos!

  8. 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.

  9. 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.

  10. 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?

  11. 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!

  12. 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.

  13. Greetings! This is my 1st comment here so I just wanted to give a quick shout out and say I genuinely enjoy
    reading your blog posts. Can you recommend any other
    blogs/websites/forums that deal with the same subjects? Appreciate it!

  14. 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.

  15. 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!!

  16. 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.

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

    When I look at your blog in Ie, it looks fine but
    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!

  18. 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.

  19. 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.

  20. 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
    share some stories/information. I know my readers would appreciate your work.
    If you are even remotely interested, feel free to
    shoot me an e mail.

  21. Hello would you mind letting me know which web host you’re utilizing?
    I’ve loaded your blog in 3 different browsers and I must say this blog loads a lot quicker then most.
    Can you recommend a good internet hosting provider at a fair
    price? Thanks a lot, I appreciate it!

  22. 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.

  23. 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.

  24. 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!

  25. 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!

  26. 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?

  27. 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.

  28. 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!

  29. 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

  30. 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!

  31. 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!

  32. 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?

  33. 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 😉

  34. 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!

  35. 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!!

  36. 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!

  37. 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.

  38. 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.

  39. 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

  40. 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!

  41. 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.

  42. 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.

  43. 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.

  44. 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.

  45. 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

  46. 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.

  47. 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.

  48. 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!

  49. 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.
    Fine with your permission allow me to grab your RSS feed to keep updated with forthcoming
    post. Thanks a million and please keep up the enjoyable work.

  50. 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.

  51. 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
    to write some content for your blog in exchange for a link back to mine.
    Please shoot me an email if interested. Thanks!

  52. 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

  53. 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.

  54. 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!

  55. 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!

  56. 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!

  57. 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!

  58. 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!

  59. 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.

  60. 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.

  61. 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.

  62. 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.

THOÁT KHỎI BÌNH LUẬN

Please enter your comment!
Please enter your name here