subquery

Same sub-query used multiple times in a single query

…衆ロ難τιáo~ 提交于 2021-01-22 05:15:02
问题 I am running a query that contains same sub-query used multiple times in a WHERE clause. I have a table having tow fields client_id , buyer_id . The sub-query returns the list of dates to be excluded from the result. This is how I am using it. SELECT id, client_id, buyer_id FROM relation WHERE client_id NOT IN (SELECT <some_id> FROM <some_table> WHERE ...) AND buyer_id NOT IN (SELECT <some_ids> FROM <some_table> WHERE ...) This is working as expected but what bothers me that there are two

Same sub-query used multiple times in a single query

删除回忆录丶 提交于 2021-01-22 05:11:52
问题 I am running a query that contains same sub-query used multiple times in a WHERE clause. I have a table having tow fields client_id , buyer_id . The sub-query returns the list of dates to be excluded from the result. This is how I am using it. SELECT id, client_id, buyer_id FROM relation WHERE client_id NOT IN (SELECT <some_id> FROM <some_table> WHERE ...) AND buyer_id NOT IN (SELECT <some_ids> FROM <some_table> WHERE ...) This is working as expected but what bothers me that there are two

Is there a way to give a subquery an alias in Oracle 11g SQL?

房东的猫 提交于 2021-01-21 00:00:08
问题 Is there a way to give a subquery in Oracle 11g an alias like: select * from (select client_ref_id, request from some_table where message_type = 1) abc, (select client_ref_id, response from some_table where message_type = 2) defg where abc.client_ref_id = def.client_ref_id; Otherwise is there a way to join the two subqueries based on the client_ref_id. I realize there is a self join, but on the database I am running on a self join can take up to 5 min to complete (there is some extra logic in

Is there a way to give a subquery an alias in Oracle 11g SQL?

我怕爱的太早我们不能终老 提交于 2021-01-20 23:54:35
问题 Is there a way to give a subquery in Oracle 11g an alias like: select * from (select client_ref_id, request from some_table where message_type = 1) abc, (select client_ref_id, response from some_table where message_type = 2) defg where abc.client_ref_id = def.client_ref_id; Otherwise is there a way to join the two subqueries based on the client_ref_id. I realize there is a self join, but on the database I am running on a self join can take up to 5 min to complete (there is some extra logic in

Select SUM from subquery while using whereHas in Laravel

一个人想着一个人 提交于 2021-01-20 11:51:48
问题 I have 2 tables, customers and customer_invoices , and I want to get all the customers with a condition on their invoices, and select specific columns (customers.id, customers.last_name, and the sum of the total_price of the invoices for each customer), I have this query : $result = Customer::whereHas('customerInvoices', function(Builder $q) { $q->where('customer_invoices.status', 1); })->select([ 'customers.id', 'customers.last_name', \DB::raw('SUM(customer_invoices.total_price) as sum') ])-

JPA subquery in from clause

别说谁变了你拦得住时间么 提交于 2020-12-05 17:32:10
问题 We're developing a web application which uses EJB to connect to a database. In our DB model, we have a mobile devices table, another one with features, and the last one that maps the values of the features with the phone models. models (id_model,...) features (id_feature, ...) model_features (id_model, id_feature, value) We want to perform a query that gets the models ordered by the number of matching features. It's to say, we pass a list of features to match (i.e. from 1 to 9), and we want