HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Notes
  2. /COUNT, SUM, AND and OR: Quick Revision
Computer Science

COUNT, SUM, AND and OR: Quick Revision

A brief note on COUNT, SUM, AND and OR: counting and adding records, joining two conditions, ranges, and a method for reading, completing and correcting SQL scripts, with practice, a program and questions to check yourself.

StemPy LabWritten by StemPy Lab
Log in to save

A brief note on COUNT, SUM, AND and OR. Read it before a test. Try each question at the end before you open its answer.

COUNT and SUM

  • COUNT(*): the number of records that pass. One number.
  • SUM(Field): the total of a numeric field over the records that pass. One number.
  • "How many orders?" is COUNT. "How many items?" is SUM of the items field.

AND and OR

  • AND: both parts true. Usually fewer records.
  • OR: at least one part true. Each record is output once.
  • Range: Field >= low AND Field <= high.
  • Outside a range: Field < low OR Field > high.
  • Each part needs its own field: Day = 'Mon' OR Day = 'Tue'.

Reading a script

  1. FROM: the table.
  2. WHERE: keep the records that pass.
  3. COUNT or SUM: one number, if present.
  4. ORDER BY: sort.
  5. SELECT: write only the chosen fields.

Correcting a script

  • Clause order: SELECT, FROM, WHERE, ORDER BY.
  • Commas between fields, none after the last.
  • Names spelled as in the table; text in quotes.
  • ASC or DESC after the field.

Practice with new numbers

A program to try

The program counts and adds with two conditions, first joined with AND and then with OR.

Read it first. Predict the four numbers, then run it.

1. Change Hours > 4 to Hours > 7. Which numbers change?

Mistakes to avoid

  • COUNT for a total. A total is SUM.
  • AND for "either". Either is OR.
  • Counting twice with OR. A record that meets both parts counts once.
  • A list as the output of SUM. It is one number.

Check yourself

  1. A field holds 333, 666 and 999. What does SUM give for it?
  1. Which joins two conditions so that both must be true?
  1. Write a condition for marks from 404040 to 606060, including both ends.
  1. 666 records pass A, 444 pass B and 222 pass both. How many pass A OR B?
  1. Which step is last when you work out the output of a script?

Sources

  • Cambridge International, IGCSE Computer Science 0478 syllabus (exams in 2026, 2027 and 2028), section 9 Databases, learning outcome 4.
← All Notes
← SELECT, WHERE and ORDER BY: Quick RevisionNOT, AND and OR Gates: Quick Revision →
More onComputer Science › Databases and SQL

Discussion (0)

Log in to join the discussion.

Loading…

On this page

  1. COUNT and SUM
  2. AND and OR
  3. Reading a script
  4. Correcting a script
  5. Practice with new numbers
  6. A program to try
  7. Mistakes to avoid
  8. Check yourself
  9. Sources

Goes with the lesson

  1. Reading, completing and correcting SQL scriptsSQL: SUM, COUNT, AND, OR and Reading Query Output

More notes on this topic

  1. SELECT, WHERE and ORDER BY: Quick Revision
  2. Database Tables and Keys: Quick Revision
  3. Logic Circuits and Truth Tables: Quick Revision
  4. NAND, NOR and XOR Gates: Quick Revision
  5. NOT, AND and OR Gates: Quick Revision
All notes on this topic →