现在有个表:A(id,name,register),B(id,groupId);C(id,name2)
写出下面的sql语句
1,统计A表中每个月注册用户数
2,统计A表中有姓名相同的用户数
3,如果表A中有姓名相同的用户,把相同的查出,写入表C中
4,A中id有多个相同的数据,A中姓名相同的Id只保留注册时间最大的
1\SELECT TO_CHAR(REGISTER, 'YYYYMM') AS MONTH, COUNT(*) FROM A GROUP BY TO_CHAR(REGISTER, 'YYYYMM');
2\SELECT COUNT(*) FROM (SELECT NAME FROM A GROUP BY NAME HAVING COUNT(*) > 1);
3\INSERT INTO C
SELECT A.ID, A.NAME
FROM A
INNER JOIN (SELECT NAME FROM A GROUP BY NAME HAVING COUNT(*) > 1) B ON A.NAME = B.NAME;
4\SELECT MAX(REGISTER), ID, NAME
FROM A
GROUP BY ID, NAME;