ควิซ SQL: COUNT(*) vs COUNT(column)

COUNT(*), COUNT(column) and COUNT(DISTINCT column) look alike but count different things. This SQL quiz tests how each one treats NULL, empty strings and duplicates, with a classic trap or two.

ปานกลาง 10 ข้อ ~6 นาที ผ่านที่ 80% SQLite

เลือกโหมด

กำลังเล่นแบบผู้เยี่ยมชม: เข้าสู่ระบบเพื่อเก็บ XP และ streak

ตัวอย่างคำถาม

ข้อ 1 จาก 10

What does this query return?

CREATE TABLE customers (name TEXT, email TEXT, phone TEXT);
INSERT INTO customers VALUES ('Ana', 'a@x.com', NULL), ('Ben', NULL, NULL), ('Cy', 'c@x.com', '555'), ('Dee', 'a@x.com', NULL);
SELECT COUNT(*), COUNT(email) FROM customers;
ดูเฉลย

D. 4|3 COUNT(*) counts all 4 rows. COUNT(email) skips the row where email is NULL, so it returns 3.

ควิซนี้มีเนื้อหาอะไรบ้าง

  • COUNT(*) counts rows, COUNT(column) counts non-NULL values
  • COUNT(DISTINCT column) and duplicates
  • COUNT(1) is the same as COUNT(*)
  • Finding missing values with COUNT(*) - COUNT(column)
  • Empty strings are not NULL

คำถามที่พบบ่อย

ต้องมีบัญชีไหม?

ไม่ต้อง ใครก็เล่นได้ เข้าสู่ระบบเพื่อเก็บ XP, streak, เหรียญตรา และประวัติ

ทำซ้ำได้ไหม?

ได้ ระบบเก็บคะแนนที่ดีที่สุดไว้ และสลับคำถามกับตัวเลือกใหม่ทุกครั้ง