SQL COMMAND

  • Add table
CREATE TABLE bedrecord (
id PRIMARY KEY SERIAL,
bedname TEXT NOT NULL,
status TEXT NOT NULL,
ts TIMESTAMP DEFAULT NOW())
  • Alter table
ALTER TABLE bedrecord
DROP COLUMN ts;
  • query by time range
SELECT * FROM bedrecord WHERE extract(hour from ts) = 17;
  • Join query
SELECT s.number, s.name, l.busstop
FROM busstop s JOIN busline l ON s.number=l.busstop
WHERE s.number='22009'