selectCASEWHEN subquery.sum = 0 or subquery.sum is null THENSUBSTR (JNL. FIELD522, 1, 2)endfrom FCM_BDPVIEWX$ (version_num} . FCM_ABR_F_TBFTJNL_S JNLleft Join (SELECT SUM (INSTR (concat (JNL. FIELD522, "\n", JNL. FIELD523, "\n', JNL. FIELD524, "\n', JNL, FIELD525) ,UPPER (PRM. NATIONALITY) ) ) sumFROM BDSP_FHTS60015 (version_num) . PARA_ NATIONALITY PRM )subquery on 1=1 改成hive写法
时间: 2024-02-16 14:02:47 浏览: 56
下面是将该查询转换为 Hive SQL 语法的示例:
```
SELECT
CASE
WHEN subquery.sum = 0 OR subquery.sum IS NULL
THEN SUBSTR(JNL.FIELD522, 1, 2)
END
FROM
FCM_ABR_F_TBFTJNL_S JNL
LEFT JOIN (
SELECT
SUM(INSTR(CONCAT(JNL.FIELD522, "\n", JNL.FIELD523, "\n", JNL.FIELD524, "\n", JNL.FIELD525), UPPER(PRM.NATIONALITY))) sum
FROM
BDSP_FHTS60015.PARA_NATIONALITY PRM
) subquery ON 1 = 1;
```
在 Hive 中,字符串拼接使用`CONCAT`函数,字符串换行可以使用`\n`,字符串转换成大写可以使用`UPPER`函数。此外,Hive 中的表名需要包含数据库名称,因此需要将`version_num`替换为实际的数据库名称。
相关问题
select a.id,SUM(CASE WHEN d.shoukuan_month = '2023-05' and d.is_del = 0 then d.netincome ELSE 0 end) as one_shoukuan,SUM(CASE WHEN d.shoukuan_month = '2023-04' AND d.is_del = 0 THEN d.netincome ELSE 0 END) as two_shoukuan,(CASE WHEN b.month = '2023-05' THEN b.create_income ELSE 30000 END) as one_income,(CASE WHEN b.month = '2023-04' THEN b.create_income ELSE 30000 END) as two_income from a left join b on b.kefuid = a.id left join d on d.kefuid = a.id where a.brand = '1' and a.is_del = 0 and a.is_lizhi = 0 group by a.id这个sql如何让select 中的d.one_shoukuan >= b.one_income and d.two_shoukuan >= b.two_income
你可以将该 SQL 作为一个子查询,在外部 SELECT 语句中添加一个 WHERE 子句来实现该要求:
```sql
SELECT *
FROM (
SELECT a.id,
SUM(CASE WHEN d.shoukuan_month = '2023-05' AND d.is_del = 0 THEN d.netincome ELSE 0 END) AS one_shoukuan,
SUM(CASE WHEN d.shoukuan_month = '2023-04' AND d.is_del = 0 THEN d.netincome ELSE 0 END) AS two_shoukuan,
(CASE WHEN b.month = '2023-05' THEN b.create_income ELSE 30000 END) AS one_income,
(CASE WHEN b.month = '2023-04' THEN b.create_income ELSE 30000 END) AS two_income
FROM a
LEFT JOIN b ON b.kefuid = a.id
LEFT JOIN d ON d.kefuid = a.id
WHERE a.brand = '1' AND a.is_del = 0 AND a.is_lizhi = 0
GROUP BY a.id
) AS subquery
WHERE subquery.one_shoukuan >= subquery.one_income AND subquery.two_shoukuan >= subquery.two_income;
```
这样,子查询将返回每个客服的 `one_shoukuan`,`two_shoukuan`,`one_income` 和 `two_income` 值,而外部查询将筛选出满足 `one_shoukuan >= one_income` 和 `two_shoukuan >= two_income` 的记录。
SELECT subquery.COMPANY_SEGMENT, subquery.one, subquery.two FROM ( SELECT COMPANY_SEGMENT, SUM(ABS(DEBIT)) - SUM(ABS(CREDIT)) AS one FROM INTELLIGENT_ADDITIVE_DEDUCT WHERE IS_FLAG = 0 AND ACCOUNT_SEGMENT = '2104020102' AND STAT_MON = '202307' GROUP BY COMPANY_SEGMENT UNION ALL SELECT COMPANY_SEGMENT, SUM(ABS(CREDIT)) - SUM(ABS(DEBIT)) AS two FROM INTELLIGENT_ADDITIVE_DEDUCT WHERE IS_FLAG = 0 AND ACCOUNT_SEGMENT = '2104020900' AND STAT_MON = '202307' GROUP BY COMPANY_SEGMENT ) subquery
您提供的查询语句已经进行了正确的修改。以下是您提供的查询语句的修改版本:
```sql
SELECT subquery.COMPANY_SEGMENT, subquery.one, subquery.two FROM (
SELECT
COMPANY_SEGMENT,
SUM(ABS(DEBIT)) - SUM(ABS(CREDIT)) AS one
FROM
INTELLIGENT_ADDITIVE_DEDUCT
WHERE
IS_FLAG = 0
AND ACCOUNT_SEGMENT = '2104020102'
AND STAT_MON = '202307'
GROUP BY
COMPANY_SEGMENT
UNION ALL
SELECT
COMPANY_SEGMENT,
SUM(ABS(CREDIT)) - SUM(ABS(DEBIT)) AS two
FROM
INTELLIGENT_ADDITIVE_DEDUCT
WHERE
IS_FLAG = 0
AND ACCOUNT_SEGMENT = '2104020900'
AND STAT_MON = '202307'
GROUP BY
COMPANY_SEGMENT
) AS subquery;
```
在上述查询中,我们使用了子查询,并将其命名为 "subquery"。子查询根据不同的条件分别计算了 "one" 和 "two" 列的值,并将它们的结果与 "COMPANY_SEGMENT" 列一起返回。
请注意,根据您的实际数据库结构和数据需求,您可能需要进行一些修改来适应您的环境。
阅读全文