一个子查询小问题
tablename:STU_INFO
stu_id name sex age department
0001 liqi m 24 sia-2
0002 yanxiaohui m 23 sia-2
0003 zhanghao m 24 sia-2
0004 liweichao m 23 sia-2
0005 liqizong m 24 sia-3
0006 changfei m 24 sia-1
0007 liqi m 24 sia-2
SQL语句:
SELECT name, COUNT(name) AS 学生数量 FROM (SELECT * FROM STU_INFO WHERE name LIKE '%l%') AS T GROUP BY name;
SELECT name, COUNT(name) AS 学生数量 FROM (SELECT * FROM STU_INFO WHERE name LIKE '%l%') GROUP BY name;
第一条语句可以查出所有名字中带“l”的学生,而第二条却报错,只不过少了“AS T”而已嘛。
谁能指点下迷津,谢谢!