Skip to content

Tag: subquery

Extract the record for last hour for specific date

I am trying to extract the last hour (TKT_DT) record for number of tickets (TKT_DN) from sales table (PS_TKT_HIST) for specific date (BUS_DAT). I have the following code but it extracts the number of tickets (TKT_NO) for each hour. I want to filter the last hour only. Here is the code I used: I get the flowing results I want

BigQuery – Scalar subquery produced more than one element –

I have this query that helps me to find separate key words within strings (very useful with utm_campaign and utm_content): For example: if I have a umt_campaign like this: us_latam_mkt_google_black-friday_audiencie-custom_NNN-NNN_nnn_trafic_responsiv The query from above will help me to separate each word with a _ in between. So I’ll have a result like this: utm_campaign country product budget source campaign audience

How to use Left Join in subquery SQL Server?

I am trying to use left join in subquery in SQL Server. My query looks fine to me but it gives syntax error. This is my query: This is the error I’m getting: This is my table structure: Answer As @Chris mentioned, the query is bit incomplete. I guess you are trying to do something like this: This query worked

SQL subquery in SELECT clause

I’m trying to find admin activity within the last 30 days. The accounts table stores the user data (username, password, etc.) At the end of each day, if a user had logged in, it will create a new entry in the player_history table with their updated data. This is so we can track progress over time. accounts table: id username

‘WITH’ clause does not work with in operator

I have a simple query: It should create a MaxSal temporary table and then in the WHERE section it should check whether the Salary, DepId are inside said table. Unfortunately, this query gives me ORA-00920: invalid relational operator which I guess is referring to the in operator. If I put the Sub-query directly instead of first putting it in a