学习 准备 尝试 谨慎小心

0%

220-Database/MySQL/MySQL问题总结

  1. select count(e.*)

    1
    -- 查询部门gZJiXoCUOo下员工的数量
    2
    select count(e.*)
    3
    from emp e
    4
    join dept d on d.deptno=e.deptno
    5
    where d.dname='gZJiXoCUOo';

    会提示错误:

    1
    mysql> select count(e.*)
    2
        -> from emp e
    3
        -> join dept d on d.deptno=e.deptno
    4
        -> where d.dname='gZJiXoCUOo';
    5
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*)
    6
    from emp e
    7
    join dept d on d.deptno=e.deptno
    8
    where d.dname='gZJiXoCUOo'' at line 1

    正确的SQL语句应该是:

    1
    select count(*)
    2
    from emp e
    3
    join dept d on d.deptno=e.deptno
    4
    where d.dname='gZJiXoCUOo';