insert into probclass (jobid, tag, probability)
(select s1.jobid, s1.tag, (select count(*) from sqlset as s2
where s1.jobid = s2.jobid and s1.tag = s2.tag)
/
(select count(*) from sqlset as s3
where s1.jobid = s3.jobid)
from sqlset as s1)我是SQL的新手,但我正在尝试编写一个尽可能简单的查询。这是一个简单的查询,它计算具有相同'jobid‘的attr 'tag’的概率。我知道这是糟糕的编码,因为枚举数和分子数一次又一次地重复计算(即每次都是如此)。
有没有简单的O(n)查询?(简单地说,我的意思是不要使用很多子句,如WITH等。)
发布于 2015-12-08 20:55:22
试着简单地说
select count(*) as 'count1' into #temp1 from sqlset as s2
where s1.id = s2.id and s1.tag = s2.tag和
select count(*) as 'count2' into #temp2 from sqlset as s3
where s1.id = s3.id如果这两者对于不同表是不同的计数值,那么
insert into probclass (id, tag, probability)
(select s1.id, s1.tag, (select count1 from #temp1/select count2 from #te,p2))https://stackoverflow.com/questions/34151723
复制相似问题