如何将SQL查询转换为HiveSQL并获取最小日期?

时间:2020-01-25 21:34:55

标签: sql hiveql pyspark-sql databricks datepart

如何将SQL查询转换为HiveSQL并获取最小日期,而不是使用datepart如下:

async function requestPlayersProfile(SteamID64) {
  return new Promise((resolve, reject) => {
    csgo.requestPlayersProfile(SteamID64, function(ranking) {
      resolve(ranking);
    });
  });
}

async function wait(ms) {
  return new Promise(resolve => {
    setTimeout(resolve, ms);
  });
}

pool.getConnection(function(err, connection) {
  if (err) throw err;
  connection.query("SELECT * FROM Users WHERE SteamID64 IS NOT NULL", async function(
    err,
    rows,
    fields
  ) {
    connection.release();
    if (err) throw err;
    for(const row of rows) {
      const ranking = await requestPlayersProfile(ow.SteamID64);
      var rankid = ranking.ranking.rank;
      var wins = ranking.ranking.wins;
      var private = ranking.player_level;

      console.log("=================================");
      console.log("SteamID: " + `${row.SteamID64}`);
      console.log("Rank: " + rank);
      console.log("Wins: " + wins);
      console.log("Private Rank: " + private);
      console.log("=================================");

      await wait(1000);
    }
  });
});

-此代码在数据块中返回错误。

1 个答案:

答案 0 :(得分:1)

对于Hive> = 1.3.0,请使用quarter(date)函数,对于Hive <1.3.0,请使用ceil(month(date) / 3.0)作为季度

select 
      min(cast(concat(year(startdate),quarter(startdate)) as bigint)) as st_dte, 
      max(cast(concat(year(enddate),quarter(enddate)) as bigint))     as end_dte, 
      a_id, 
      carr as bar_code, 
      case when wac < 100 then 'Dom Flg bar' else 'Int Flg bar' end as bar_flag, 
      case when a_id in (343, 455, 123, 656, 645) then 1 else 0 end as lcc_bar 
from oair_cardecode 
group by a_id, carr, 
      case when wac < 100 then 'Dom Flg bar' else 'Int Flg bar' end, 
      case when a_id in (343, 455, 123, 656, 645) then 1 else 0 end;