Updated on 2024-06-03 GMT+08:00

Conditional Queries

A conditional query retrieves data that meets the conditions.

-- Create a table and insert data into the table.
gaussdb=# CREATE TABLE test_grade(
    id INT, 
    name VARCHAR(20),
    score FLOAT       -- Score
);
gaussdb=# INSERT INTO test_grade VALUES (1,'Scott',90),(2,'Jack',87.5),(3,'Ben',48);

-- Query information about students who fail to pass the test.
gaussdb=# SELECT * FROM test_grade WHERE score < 60;
 id | name | score 
----+------+-------
  3 | Ben  |    48
(1 row)

-- Delete.
gaussdb=# DROP TABLE test_grade;