I’m working on writing a SQL query that would allow me to find customers who bought a certain variety of a product during specific sale dates and then subsequently bought a different product within a different date range. I want to use a subquery in the from clause to search for the second group of customers within the first group
Tag: subquery
subquery calculate days between dates
Sub query, SQL, Oracle I’m new to sub queries and hoping to get some assistance. My thought was the sub query would run first and then the outer query would execute based on the sub query filter of trans_code = ‘ABC’. The query works but it pulls all dates from all transaction codes, trans_code ‘ABC’ and ‘DEF’ ect. The end
Missing expression inside sub-query statement?
I am using the infamous “CityJail” schema to answer a question “List the names of all criminals who have committed more than average number of crimes and aren’t listed as violent offenders.” Here is my code: but I get an error: ORA-00936: missing expression 00936. 00000 – “missing expression” *Cause: *Action: Error at Line: 7 Column: 22 When I change
Cumulative balance across two tables
I want to get data from 2 tables ordering them by date: to get the cumulative balance for the customer The 2 tables that I want to get data from are my tables: transfers & trans_payments transfers:…
Finding the most active video maker within multiple tables(SQLite)
How can I find the initials of the most active video maker, the one that made the most videos considering the following tables using only one query? CREATE TABLE IF NOT EXISTS Videos ( title TEXT …
Find first available value that doesn’t exist
I want to create table for book chapters where pk will be book_id and chapter_internal_number. I’m not sure how find next free chapter_internal_number value for new chapter insert (chapter can be deleted and it’s chapter_internal_number value should be reused). How to find first chapter_internal_number avaiable value for book? Avaiable value is next value that doesn’t exist in ASC order. Table
check if value is available in DB or not
I have a table which has the schema: i need a query for the report which contains whether the name i give exists in the DB . the name AD,BC,CA should be given by me and its not in any other table. Thanks in advance Answer Use an outer join against a values list:
How to join queries with a subquery?
So I’m a total newbie trying to solve this exercise where I have to find all the dishes that are marked as Vegetarian but contain Turkey meat in their ingredients. This is what I’ve tried (this is where I inner join 3 tables to find the ingredients): this is where I can’t seem to be able to join the subquery
Hive: randomly select N values from distinct values of one column
Suppose I have a dataset like this I would like to randomly select, say, 3 values from the distinct ID values. One possibility is to get a table like this How shall I do that in Hive? Answer Here is one option using a join and rand(): The subquery randomly selects 3 ids, then the outer query brings all related
How to use LOWER() on elements of a jsonb column in PostgreSQL?
I have a PostgreSQL table like this one: Table t id | keys (jsonb) —+—————- 1 | [“Key1”, “Key2”] My goal is to query this table to find out if one of the keys of a …