SELECT DISTINCT Category_Desc FROM tt_table_ti t1 JOIN tt_table t2 ON t1.yyyymm = t2.yyyymm AND t1.SKU = t2.SKU AND t1.yyyymm ='201901' WHERE (charindex (t1.ad_code, 'All') > 0 or 'All'= 'All')
上述sql出现内存溢出的原因是因为t1表和t2表都比较大都是十几万的数据量两者jion后再去重使得数据两年更多再去重时极大的浪费内存,和资源,因此想此类种的表之间的join应多加注意,