Oracle数据库SQL常用语句

1.选出表中字段名出现过两次及以上的记录

select * from table_name where column_name in (select column_name from table_name where colunm1_name = '123' and column2_name = '456' group by column_name having count(1)>=2)

2.两表联合查询:表1和表2有相同的字段名id,表1有字段名city,表2有字段名money,统计每个city的sum(money)

select city, sum(money) from (select table1.city, table2.money from table1,table2 where table1.id = table2.id) group by city

3.选出表中一个字段每个值出现的次数

select column_name, count(*) from table_name group by column_name

4.group by后再order by排序

select colunm_name, count(*) as num from table_name group by colunm_name order by num

5.复制一个表的结构到新表中

create table B as select * from A where 1=2;

6.将表1的数据复制到表2中

insert into table2 select * from table1;

7.varchar转decimal

select name,cast(age/(select sum(age) from boss) as decimal(32,2)) as age from boss;

未完待续。。。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值