Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. id name city salary dept
  2.  
  3. SELECT salary WHERE salary > (SELECT AVG(salary) FROM *)
  4.  
  5. select * from b where ref > (select avg(ref) from b);
  6. select * from b having ref > (select avg(ref) from b);
  7.  
  8. mysql> select * from b;
  9. +------+------------+------+
  10. | id | d2 | ref |
  11. +------+------------+------+
  12. | 300 | 2010-12-12 | 3 |
  13. | 300 | 2011-12-12 | 2 |
  14. | 300 | 2012-12-12 | 1 |
  15. | 400 | 2011-12-12 | 1 |
  16. +------+------------+------+
  17. 4 rows in set (0.00 sec)
  18.  
  19. mysql> select * from b having ref > avg(ref);
  20. +------+------------+------+
  21. | id | d2 | ref |
  22. +------+------------+------+
  23. | 300 | 2010-12-12 | 3 |
  24. +------+------------+------+
  25. 1 row in set (0.00 sec)
  26.  
  27. mysql> select * from b having ref > (select avg(ref) from b);
  28. +------+------------+------+
  29. | id | d2 | ref |
  30. +------+------------+------+
  31. | 300 | 2010-12-12 | 3 |
  32. | 300 | 2011-12-12 | 2 |
  33. +------+------------+------+
  34. 2 rows in set (0.02 sec)
  35.  
  36. mysql> select * from b where ref > (select avg(ref) from b);
  37. +------+------------+------+
  38. | id | d2 | ref |
  39. +------+------------+------+
  40. | 300 | 2010-12-12 | 3 |
  41. | 300 | 2011-12-12 | 2 |
  42. +------+------------+------+
  43. 2 rows in set (0.00 sec)
  44.  
  45. mysql> select *,avg(ref) from b having ref > avg(ref);
  46. +------+------------+------+----------+
  47. | id | d2 | ref | avg(ref) |
  48. +------+------------+------+----------+
  49. | 300 | 2010-12-12 | 3 | 1.7500 |
  50. +------+------------+------+----------+
  51. 1 row in set (0.00 sec)
  52.  
  53. SELECT Salary
  54. FROM (
  55. SELECT
  56. Salary,
  57. AVG(Salary) OVER () AS AvgSalary
  58. FROM atable
  59. ) s
  60. WHERE Salary > AvgSalary
  61.  
  62. SELECT *FROM table_name WHERE salary > avg(select salary from table_name)
  63.  
  64. select empno,e.deptno,sal
  65. from emp e, ( select deptno,avg(sal) avsal
  66. from emp
  67. group by deptno
  68. ) a
  69. where e.sal > a.avsal
  70. and e.deptno = a.deptno;
  71.  
  72. select salary from Employee where salary > (select ava(salary) from employee)
  73.  
  74. select e1.* from emp e1 inner join (select avg(sal) avg_sal,dept_id from emp group by
  75. dept_id) as e2 on e1.dept_id=e2.dept_id and e1.sal>e2.avg_sal
  76.  
  77. select * from emp where sal > (select avg(sal) from emp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement