当前位置:Gxlcms > 数据库问题 > PostgreSQL练习3

PostgreSQL练习3

时间:2021-07-01 10:21:17 帮助过:27人阅读

select dname,count(ename),avg(sal),sum(sal)
from emp e,dept d
where e.deptno=d.deptno
group by dname;

select dname,count(ename),avg(sal),sum(sal)
from emp e inner join dept d
on e.deptno=d.deptno
group by dname;

psql -h 192.168.0.100 -U testuser
create database testdb
\c testdb

SELECT *
FROM sdb."Student" as a
where a.Sid in (‘01‘,‘02‘)
intersect
SELECT *
FROM sdb."Student" as b
where b.Sid in (‘01‘)

SELECT *
FROM sdb."Student" as a
where a.Sid in (‘01‘,‘02‘)
intersect all
SELECT *
FROM sdb."Student" as b
where b.Sid in (‘01‘)

SELECT *
FROM sdb."Student" as a
where a.Sid in (‘01‘,‘02‘)
union all
SELECT *
FROM sdb."Student" as b
where b.Sid in (‘01‘)

SELECT *
FROM sdb."Student" as a
where a.Sid in (‘01‘,‘02‘)
union
SELECT *
FROM sdb."Student" as b
where b.Sid in (‘01‘)

SELECT *
FROM sdb."Student" as a
where a.Sid in (‘01‘,‘02‘)
union all
SELECT *
FROM sdb."Student" as b
where b.Sid in (‘01‘)

SELECT *
FROM sdb."Student" as a
where a.Sid in (‘01‘,‘02‘)
except
SELECT *
FROM sdb."Student" as b
where b.Sid in (‘01‘)

SELECT *
FROM sdb."Student" as a
where a.Sid in (‘01‘,‘02‘,‘03‘)
except all
SELECT *
FROM sdb."Student" as b
where b.Sid in (‘01‘)

select s.Sid
FROM sdb."Student" as s
left join sdb.sc
on s.Sid=sc.Sid
group by s.Sid
having count(sc.Cid)<(select count(Cid) from sdb.course);

select abs(-11);
select mod(123,6);
select ceil(1.1);
select floor(1.9);
select round(123.123,0);
select trunc(123.123,3);
select ascii(‘A‘);
select chr(66);
select lower(‘SQL‘);
select upper(‘asd‘);
select initcap(‘sda‘);
select substr(‘asdfgh‘,2,3);
select length(‘SQL‘);
select position(‘r‘in ‘string‘);
select lpad(‘h‘,10,‘*‘);
select rpad(‘g‘,10,‘*‘);
select trim(‘s‘from ‘string‘);
select replace(‘ASD‘,‘SD‘,‘sd‘);

select current_date;
select current_time;
select extract(day from timestamp ‘2019-10-17 14:05:40‘);--从日期时间轴里抽取子域
select date_trunc (‘month‘,now());

select current_time+time‘00:00:01‘;
select current_time+time‘00:01‘;
select current_time+time‘01:00‘;
select current_time+interval‘1 day‘;
select current_time+interval‘1 week‘;
select current_time+interval‘1 month‘;


select to_char(current_timestamp,‘HH12:MI:SS‘);
select to_char(interval‘15h 2m 12s‘,‘HH24:MI:SS‘);
select to_char(125,‘999‘);
select to_char(125.8::real,‘99909‘);
select to_date(‘05 Dec 2000‘,‘DD MON YYYY‘);
select to_number(‘12.454.8-‘,‘99G999D99S‘);
select to_timestamp(‘05 Dec 2000‘,‘DD MON YYYY‘);

select current_database();--当前数据库名字
select current_schema();--当前模式名字
select current_user;--当前环境下用户名
select version();--版本信息

 

PostgreSQL练习3

标签:run   val   osi   HERE   rac   rom   trim   avg   用户   

人气教程排行