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

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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵