SELECT purchase_monetary ,PERCENTILE_CONT(0.3) WITHINGROUP (ORDERBY purchase_monetary) OVER () AS num_30q ,PERCENTILE_CONT(0.7) WITHINGROUP (ORDERBY purchase_monetary) OVER () AS num_70q from( SELECT purchase_monetary from online_purchase where master_id in (10133982217,10123311972) )tt
-- 3分位数 select purchase_monetary, purchase_monetary_per from( select purchase_monetary, purchase_monetary_per ,row_number() over(partitionby purchase_monetary_per orderby purchase_monetary) rn from ( select purchase_monetary ,convert( decimal(18, 2) ,PERCENT_RANK() over (orderby purchase_monetary)) as purchase_monetary_per from online_purchase where master_id in (10133982217,10123311972) )tt where purchase_monetary_per>=0.3and purchase_monetary_per <0.4 )ttt where rn=1
--7分位数 select purchase_monetary, purchase_monetary_per from( select purchase_monetary, purchase_monetary_per ,row_number() over(partitionby purchase_monetary_per orderby purchase_monetary) rn from ( select purchase_monetary ,convert( decimal(18, 1) ,PERCENT_RANK() over (orderby purchase_monetary)) as purchase_monetary_per from online_purchase where master_id in (10133982217,10123311972) )tt where purchase_monetary_per>=0.6and purchase_monetary_per <=0.7 )ttt where rn=1
select t1.name , CONCAT(t2.name ,'(' ,t1.prec,')') as datetype from( select* from syscolumns where id = object_id('DA_Tagging.media')
)t1 leftjoin systypes t2 on t1.xtype = t2.xtype where t2.[status]=0
sql server删除表里的重复数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
-- 方法一(某些数据库不支持) delete t1 from ( select*, row_number() over (partitionby dt,platform_type orderby dt,platform_type ) rn from DA_TopRanking.kpi_tracking_totalV2 ) as t1 where rn>1
-- 方法2 selectdistinct* into #temp2 from table_name
CREATEFUNCTION FNC_SPLIT(@MYSTRVARCHAR(500), @DELIMITERCHAR(1)) RETURNS@MYTBLTABLE (idx smallint, valuevarchar(8000)) AS BEGIN DECLARE@RETVARCHAR(500) DECLARE@INDEXINT DECLARE@COUNTERsmallint --Get the first position of delimiter in the main string SET@INDEX= CHARINDEX(@DELIMITER,@MYSTR) SET@COUNTER=0
--Loop if delimiter exists in the main string WHILE @INDEX>0 BEGIN --extract the result substring before the delimiter found SET@RET=SUBSTRING(@MYSTR,1, @INDEX-1 ) --set mainstring right part after the delimiter found SET@MYSTR=SUBSTRING(@MYSTR,@INDEX+1 , LEN(@MYSTR) -@INDEX ) --increase the counter SET@COUNTER=@COUNTER+1 --add the result substring to the table INSERTINTO@MYTBL (idx, value) VALUES (@COUNTER, @RET) --Get the next position of delimiter in the main string SET@INDEX= CHARINDEX(@DELIMITER,@MYSTR) END
--if no delimiter is found then simply add the mainstring to the table IF @INDEX=0 BEGIN SET@COUNTER=@COUNTER+1 INSERTINTO@MYTBL (idx, value) VALUES (@COUNTER, @MYSTR) END RETURN END
GO SELECTvalueFROM FNC_SPLIT('10133982217,10123311972,10116946693',',')
GO DROPFUNCTION FNC_SPLIT
----传入master_id select master_id,preferred_brand --,count(distinct master_id) as id_cnt from INFORMATION_SCHEMA.TABLES where master_id in (select v.value as user_id from String_Split('10133982217,10123311972,10116946693',',')v )
if not object_id(N'Tempdb..#T') isnull droptable #T createtable #T(user_id bigint) insert #T select user_id from( selectvalueas user_id from String_Split(@masteridlist , ',') )t