1. in的巨坑 CREATE TABLE #tmp1 (id INT, value int) CREATE TABLE #tmp2 (id1 INT, value int) ,),(,),(,) ,),(,),(,) SELECT * FROM #tmp1 WHERE id IN (SELECT id FROM #tmp2) DROP TABLE #tmp1,#tmp2 #tmp2没有id这个列,但是 where id in (select id from #tmp2)没有报错,而且执行成功.…
SELECT TOP 页大小 * FROM TestTable WHERE (ID > (SELECT case when count(0) < 页大小 then 0 else MAX(id) FROM (SELECT TOP 页大小*(页数-1) id FROM 表 ORDER BY id) AS T)) ORDER BY ID…
背景 -- 求每个用户的拥有的产品数,其中userid需要简单split出来 SELECT split (id, '-') [ 0 ] AS userid, count(DISTINCT productid) AS productid FROM user_product WHERE dt >= '2018-05-01' GROUP BY userid 你是不是想这样用? 报错和原因 看看报错 Invalid table alias or column reference 'userid': (p…