create table users(
id serial not null primary key,
username varchar(15) not null UNIQUE,
password text not null,
email text not null UNIQUE,
c_date timestamp default current_timestamp,full_name varchar(40) ,
status boolean not null default true,balance real not null default 0,
lastlogin timestamp not null default current_timestamp,
admin boolean not null default false
);
create table game(
id serial not null primary key,
name varchar(100) notnull UNIQUE,
price real not null CHECK (price > 0),
popularity int not null,
created_date timestamp not null default current_timestamp,
update_date timestamp not null default current_timestamp,
logo varchar(200),
genre_id int not null references genre(id));
create table sale(
id serial not null primary key,
user_id int not null references users(id),
game_id int not null references game(id),
c_date timestamp default current_timestamp,
amount real not null CHECK (price > 0));
create table genre(
id serial not null primary key,
name varchar(40) not null UNIQUE);
insert into game (name,price,popularity,genre_id) values ('Wow',100,1,1);
insert into game (name,price,popularity,genre_id) values ('Metin2',300,10,2);
Büyükten küçüğe
select * from game order by created_date desc;
Küçükten büyüğe
select * from game order by created_date asc;