I’m trying to get the top 5 comments by score for each Reddit post. I only want to retrieve the top N comments by score for each post title. Example: I only would want comment 1 and 2 for each post. …
Identify rows with particular value across multiple columns
Each row has an Id and a Category Presence/Status combo. Sample code: DECLARE @sample_table TABLE ( Id INT ,Category_Alpha BIT ,Category_Beta BIT ,Category_Charlie BIT ,…
Find most recent row per user and day in sql query
I want to find the most recent purchase per customer for each date (a customer might make multiple purchases on a given date and I want the most recent for that date). My dataframe looks something …
Track customer loss in redshift
I have a data base that looks like this. It has: acct_open_dt, or the day the account was opened. acct_close_dt, or the day the account was closed. dayssinceopendt, which is TODAY – acct_open_dt if …
Casting the Bigint number Returns NULL
I need o convert a integer value to the highest data type in hive as my value is of 25 digits NULL value will be returned for the above select stmnt; I am very well aware that the supplied number is greater than the largest number of Bigint. But we are getting such values upon which i have to calculate
How to join two tables based on FIRST VALUE of a group
Objective: I would like to join two tables based on the first value of Id column grouped by subscription Id column ordered by created_at column. Situation: Table1 looks like this: id channel …
Ranking based on two columns
Finding the Rank of the Particular User from the Database by comparing three columns. Name | Score | Attempts | Time test | 2 | 4 | 2019-01-29 19:50:11 tes2 | 2 | 1 | 2019-01-…
How to Run Two T-Sql Statement By Exec Command in SqlServer?
I want run 2 SQL queries in Exec instruction, how can I do this? ListOfLeaveRemainingInfo is a user-defined table type: When I run the stored procedure, I get this error: Msg 1087, Level 15, State 2, Line 33 Must declare the table variable “@LeaveRemainingTempTable” Answer Scratch the previous. @L…
Two indexes for same column and change the order
I have a large table in Microsoft SQL Server 2008. It has two indexes. One index having column A descending order and another index having the column A ascending with some other columns. My …
SQL Joins for Multiple Fields with Null Values
I have a table of maintenance requirements and associated monthly frequency it is to be performed maint I also have a table of equipment with data on its manufacturer, model, device type and building. equip I am trying to match each maintenance requirement with its associated equipment. Each requirement appli…