三生暮雨渡瀟瀟 2021-12-18 21:13 采纳率: 25%
浏览 154
已结题

hive查询,使用where子查询没有返回结果

问题遇到的现象和发生背景

测试where语句,第二种语句返回0行数据

问题相关代码,请勿粘贴截图

```sql
select e.* from
(select name, salary, deductions["Federal Taxes"] as ded,
  salary * (1 - deductions["Federal Taxes"]) as salary_minus_fed_taxes from employees) e
where round(e.salary_minus_fed_taxes) > 70000;
------------------------结果-------------------------------
+------------+-----------+--------+---------------------------+
|   e.name   | e.salary  | e.ded  | e.salary_minus_fed_taxes  |
+------------+-----------+--------+---------------------------+
| John Doe   | 100000.0  | 0.2    | 80000.0                   |
| John Bob   | 300000.0  | 0.4    | 180000.0                  |
| John Bill  | 200000.0  | 0.3    | 140000.0                  |
+------------+-----------+--------+---------------------------+
----------------------------第二种方式:
select name, salary, deductions["Federal Taxes"] as ded,
  salary * (1 - deductions["Federal Taxes"]) as salary_minus_fed_taxes from employees
where (select salary * (1 - deductions["Federal Taxes"]) from  employees) = 80000.0;
----------------结果--------------------------------------
+-------+---------+------+-------------------------+
| name  | salary  | ded  | salary_minus_fed_taxes  |
+-------+---------+------+-------------------------+
+-------+---------+------+-------------------------+

  • 写回答

1条回答 默认 最新

  • DarkAthena ORACLE应用及数据库设计方案咨询师 2021-12-18 21:48
    关注

    where中又使用了一次emloyees表,和上面的emloyees表没有任何关联关系,你要根据80000.0来定位数据的话,应该是像下面这样写

    select name, salary, deductions["Federal Taxes"] as ded,
      salary * (1 - deductions["Federal Taxes"]) as salary_minus_fed_taxes from employees
    where   salary * (1 - deductions["Federal Taxes"])  = 80000.0;
    

    当然我不确定你这个显示是否有小数位四舍五入,或许要改成

    round(salary * (1 - deductions["Federal Taxes"]) ,1) = 80000.0
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    问题事件

    • 系统已结题 12月26日
    • 已采纳回答 12月18日
    • 创建了问题 12月18日

    悬赏问题

    • ¥15 Latex算法流程图行号自定义
    • ¥15 关于#python#的问题:我在自己的电脑上运行起来总是报错,希望能给我一个详细的教程,(开发工具-github)
    • ¥40 基于51单片机实现球赛计分器功能
    • ¥15 cs2游戏画面卡住,应用程序sid与指挥者sid不匹配
    • ¥15 实验七:Pandas要有实验截图和代码
    • ¥15 TypeError: Make sure that the iterable only contains strings.
    • ¥35 电脑放图书馆,这是被黑了吗
    • ¥15 等高线中数据取消科学计数法
    • ¥15 Qt播放10路ffmpeg 视频流
    • ¥15 如何利用闲置机械硬盘变现