随笔分类 -  SQL(Oracle,MySQL,SQL Server)

摘要:1、在查询中根据A字段关联另一个表,并用另一个表A字段对应的另一个字段替换本表中A字段的值。 virtualid表,两列label, number;virtualid_zd表,两列name, number,查询virtualid表中各name所对应的label值: select name, (sel 阅读全文
posted @ 2021-06-26 11:30 Sunshine168 阅读(35) 评论(0) 推荐(0)
摘要:SQL语句向表中插入多个值的话,如果如下语句 INSERT INTO 某表 VALUES(各个值),VALUES(各个值),.....; 这样会报错的,因为oracle是不支持这种写法的,如果多个INSERT INTO VALUEES(各个值);这样以“;”隔开一同执行也是不行的,oracle也是不 阅读全文
posted @ 2020-11-19 17:35 Sunshine168 阅读(5321) 评论(0) 推荐(0)
摘要:必需的Oracle链接库的下载地址:https://www.oracle.com/technetwork/topics/winx64soft-089540.html 只连接数据库的话不必安装客户端: 1. 把cx_Oracle的客户端文件复制到site-packages/ 目录下,可能是Python 阅读全文
posted @ 2019-04-19 09:59 Sunshine168 阅读(5276) 评论(0) 推荐(0)
摘要:having 后面只能用 COUNT(*),不能用 cnt 阅读全文
posted @ 2017-07-25 10:31 Sunshine168 阅读(376) 评论(0) 推荐(0)
摘要:select top 100 * from ClientSecurityReturnIndex where EffectiveDate=(select MAX(EffectiveDate) from ClientSecurityReturnIndex as tb where ClientSecurityId=ClientSecurityReturnIndex.ClientSecurityId) ... 阅读全文
posted @ 2017-07-18 17:22 Sunshine168 阅读(2289) 评论(0) 推荐(0)
摘要:select AccountId,COUNT(*) as cnt from AccountReturnIndex group by AccountId having COUNT(*)<20 阅读全文
posted @ 2017-07-13 09:41 Sunshine168 阅读(1334) 评论(0) 推荐(0)
摘要:create table #Account(AccountId int) insert into #Account select 1500722090 union select 1500722091 union select 1500722092 union select 1500722316 union select 1500722317--'union' is auto filter du... 阅读全文
posted @ 2017-07-06 10:28 Sunshine168 阅读(357) 评论(0) 推荐(0)
摘要:1.随机获取n条数据 这时每次运行取到的数据都是一样的,如果想要不一样的,如下 2.随机获取10%数据 阅读全文
posted @ 2017-03-10 17:57 Sunshine168 阅读(1201) 评论(0) 推荐(0)
摘要:上面这行代码可以查出该表所有的column,改为sp_pkeys,可以查出该表的主键。但是我如果想只查出column name,select COLUMN_NAME FROM(exec sp_columns tableName) as A,这样写是不行的,必须要create一张表,把数据insert 阅读全文
posted @ 2017-01-05 16:56 Sunshine168 阅读(2731) 评论(0) 推荐(0)
摘要:在A表中存在一个字段“AccountId”,而且不同记录之间的“AccountId”值有可能会相同,现在就是需要查询出在该表中的各记录之间,“AccountId”值存在重复的项,这里count记录该字段重复的记录数(此处只针对该字段是否重复进行查询);Select AccountId,Count(* 阅读全文
posted @ 2016-07-27 11:13 Sunshine168 阅读(215) 评论(0) 推荐(0)