subquery

Changing a sql query using join instead of a subselect

此生再无相见时 提交于 2019-12-12 01:08:24
问题 i've got the following problem: Because the amount of entries could get very big, I would like to use a join instead of a subselect in a sql query. It regards the following three simplified tables: devices: - id confirmation_requests: - id - filePath confirmation - id - requestId (references confirmation_requests.id) - deviceId (references devices.id) The target is, to get all confirmation requests, which are not confirmed (with an entry in the confirmation table) by a given device. I just

How to join/subquery a second table

*爱你&永不变心* 提交于 2019-12-12 00:57:33
问题 I have two tables, one table has some information in each row along with a comma seperated list of ids that another table contains. Right now I am grabbing the data from table A (with the comma seperated ids), and I want to also grab all of the data from Table B (the table containing additional information). I would like to do this in the most efficient SQL method possible. I was thinking about joining Table B to Table A based on the ids IN the field, but I was not sure if this is possible.

Optimize performance of sub-queries

落花浮王杯 提交于 2019-12-12 00:52:29
问题 My first query from table takes about 40 seconds and creates over 80,000 rows. I want to get the counts of Windows 7 applications by Site, Sequence, Total and any OS version. These sub-queries work, but of course they slow the process down considerably. It took 3.5 hours to run. Is there a more efficient way to do this? Output: SoftwareName Sequence Site Win7/site Win7Installs/seq TotWin7apps TotalInstalls Adobe Acrobat 1 BKN 1 5 626 7854 AutoCAD LT 1 BKN 1 1 3 15 Adobe Acrobat 1 CTW 4 5 626

How do I get unique user engagements?

旧城冷巷雨未停 提交于 2019-12-12 00:47:00
问题 I am trying to list unique user engagements with the engagement_type I used to have the following query. SELECT u.id, u.fname, u.lname FROM ( SELECT id, engagement_type FROM ( SELECT user_id AS id, 'comment' FROM comments WHERE commentable_id = 48136 AND commentable_type = 'Video' UNION ALL SELECT user_id AS id, 'like' FROM likes WHERE likeable_id = 48136 AND likeable_type = 'Video' ) AS a GROUP BY id LIMIT 10 ) b JOIN users u USING (id); Returns: id | fname | lname --------------------------

Exception in getting list from CriteriaQuery

筅森魡賤 提交于 2019-12-11 23:05:10
问题 for some reason i can't tell, there is exception when i try to get a list from CriteriaQuery using subquery. some one please help!!! here is the code: public String[] getProductsDistinctBySubQueriesName(String category) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Tuple> criteria = builder.createTupleQuery(); //subquery Subquery<Integer> subqueries = criteria.subquery(Integer.class); Root<Productscategory> productCategory = subqueries.from(Productscategory.class);

NSPredicate with nested subqueries failing to compile(core data)

青春壹個敷衍的年華 提交于 2019-12-11 22:49:13
问题 My relevant part of the CoreDate DB Category<-->>Subcategory<-->>Gym<<-->>Membership I am trying to get all the Categories who have at lease one gym where the user has an active membership. I have an array with all the user's active membership uid's(every membership has a uid in the DB) I am trying the following query which fails to compile, I even decided it into substrings just to make sure no errors are made: NSString *shopsSubquery = [NSString stringWithFormat:@"(SUBQUERY($y.programs,$z,

DSUM in Access query yields Nulls in random records

不想你离开。 提交于 2019-12-11 22:22:19
问题 I have a query (in MS Access 2013) that gives me the Sales for various Items by Date, for each day for the next 12mo. In another table, I have each Item with its known purchasing leadtime, say between 30 and 90 days. I created a query, and for each Item, I calculated the future date according to the leadtime, using: FutureDate: DateAdd("d",[Leadtime],Date()) I validated all Items exist in the Sales query, and all FutureDates are within the records that exist in Sales. I need to calculate the

Using SUM() in the SELECT is better or in the SUB-SELECT?

一笑奈何 提交于 2019-12-11 21:27:53
问题 I have two query with the same result, now I want to know which one is more optimized? In the SELECT : select t1.*, sum(t2.value) as total_votes from table1 t1 left join table2 t2 on t1.id = t2.post_id In the SUB-SELECT: select t1.*, t3.total_votes from table1 t1 left join (select post_id, sum(value) as total_votes from table2 t2 group by post_id) t3 on t1.id = t3.post_id It should be noted, I have two table: table1(posts), table2(votes). And the two above query are for calculating total

MySQL Subselect issue

帅比萌擦擦* 提交于 2019-12-11 21:08:20
问题 I have an issue with a mysql subselect. **token table:** id | token | articles 1 | 12345 | 7,6 2 | 45saf | 6,7,8 **items table:** id | name | filename 6 | Some brilliant name | /test/something_useful.mp3 7 | homer simpson | /test/good-voice.mp3 **query:** SELECT items.`filename`,items.`name` FROM rm_shop items WHERE items.`id` IN ( SELECT token.`articles` FROM rm_token token WHERE token.`token` = 'token') I only get one of the two files (with the id 7 that is). What am I missing here? 回答1:

Use calculated values from subquery in another variable

我的梦境 提交于 2019-12-11 21:04:38
问题 I have a complicated sub query that displays [Days Open]. I want to use this [Days Open] as a value in a another variable. Here is a simplified code example. If I take the entire subselect and paste it wherever the second subselect=[days open] the query works it just takes 3 min. I just want the second subquery to reference the calculated value from the first subquery SELECT Sub.Category AS 'Category', SubSelect(not actually value just shortening code) As [Days Open], (Case When Sub.Category