subquery

Mongo query to sort by distinct count

冷暖自知 提交于 2019-12-24 16:03:53
问题 I have two fields 'company' and 'url'. I want to sort it by number of times distinct 'company' is occurring and then display three 'url' corresponding to that particular company. Data is stored like this: { "_id" : ObjectId("56c4f73664af6f7305f3670f"), "title" : "Full Stack Software Developer", "url" : "http://www.indeed.com/cmp/Upside-Commerce,-Inc./jobs/Full-Stack-Software-Developer-6e93e36ea5d0e57e?sjdu=QwrRXKrqZ3CNX5W-O9jEvRQls7y2xdBHzhqWkvhd5FFfs8wS9wesfMWXjNNFaUXen2pO-kyc_Qbr7-

Codeigniter subquery exists

ⅰ亾dé卋堺 提交于 2019-12-24 13:02:34
问题 Im trying to do a subquery with $this->db->where(" EXISTS (SELECT * FROM myTable)"); But it doesnt work, the output of this is: myquery + WHERE 'EXISTS (SELECT * FROM myTable); That quote before the EXISTS makes the query unresolvable! Does anyone knows how to solve it? Thanks! 回答1: please remove space before and after EXISTS keyword.that does not display any error. $this->db->where("EXISTS(SELECT * FROM myTable)"); 回答2: Maybe you could try to set the escape to false by using $this->db->where

Codeigniter subquery exists

你说的曾经没有我的故事 提交于 2019-12-24 12:55:25
问题 Im trying to do a subquery with $this->db->where(" EXISTS (SELECT * FROM myTable)"); But it doesnt work, the output of this is: myquery + WHERE 'EXISTS (SELECT * FROM myTable); That quote before the EXISTS makes the query unresolvable! Does anyone knows how to solve it? Thanks! 回答1: please remove space before and after EXISTS keyword.that does not display any error. $this->db->where("EXISTS(SELECT * FROM myTable)"); 回答2: Maybe you could try to set the escape to false by using $this->db->where

MySQL - Complicated SUMs inside Query

ε祈祈猫儿з 提交于 2019-12-24 12:43:53
问题 This is going to be tough to explain. I'm looping through my client records from tbl_customers several times a day. SELECT c.* FROM tbl_customers c I'm returning simply the customer's: customerid , name , phone , email Now the weird part. I want to append 3 more columns, after email: totalpaid, totalowed, totalbalance BUT, Those column names don't exist anywhere. Here is how I query each one: (as a single query) SELECT SUM(total) AS totalpaid FROM tbl_customers_bills WHERE customerid = X AND

Improving this MySQL Query - Select as sub-query

两盒软妹~` 提交于 2019-12-24 11:44:08
问题 I have this query SELECT shot.hole AS hole, shot.id AS id, (SELECT s.id FROM shot AS s WHERE s.hole = shot.hole AND s.shot_number > shot.shot_number AND shot.round_id = s.round_id ORDER BY s.shot_number ASC LIMIT 1) AS next_shot_id, shot.distance AS distance_remaining, shot.type AS hit_type, shot.area AS onto FROM shot JOIN course ON shot.course_id = course.id JOIN round ON shot.round_id = round.id WHERE round.uID = 78 This returns 900~ rows in around 0.7 seconds. This is OK-ish, but there

Generating a ordered sequence rank on complex query

独自空忆成欢 提交于 2019-12-24 10:46:35
问题 I am trying to create an implicit rank in the output from the query. The problem seems to be that row_number() is running before worth is calculated. SELECT firstname, lastname, personid, year, ( SELECT COALESCE(SUM(thevalue),0) FROM assets WHERE personidref = w.personid AND year = w.year ) AS assets , ( SELECT COALESCE(SUM(amount),0) FROM liabilities WHERE personidref = w.personid AND year = w.year ) AS liabilities, ( (SELECT COALESCE(SUM(thevalue),0) FROM assets WHERE personidref = w

understanding JasperReports and JRBeanCollectionDataSource

家住魔仙堡 提交于 2019-12-24 10:33:14
问题 I now have my JasperReports working from my JRBeancollectionDataSource in my code! I am just a bit confused about some things... When I am designing reports in iRepor t, I create the fields from a query, which I can do fine and all, since when I am actually running the query I'm using a a code JRBeanCollectionDataSource and so is the hql in the report totally irrelevant at this point? Also, I have List collections of other persistent objects in the ones I'm fetching for the report and I want

MySQL: Using “In” with Multiple SubQueries?

限于喜欢 提交于 2019-12-24 09:59:53
问题 I'm trying to use this query: SELECT COUNT(PF.PageID) AS Total,P.PageID FROM Pages P LEFT JOIN Pages_Filters PF ON PF.PageID=P.PageID WHERE P.PageID IN ( (SELECT PageID FROM Pages_Filters WHERE FilterID="1" AND FilterOptionID="2" ), (SELECT PageID FROM Pages_Filters WHERE FilterID="7" AND FilterOptionID="57" ) ) AND P.PageID !="283" GROUP BY PF.PageID Which produces the error: Sub-query returns more than 1 row I'd like for MySQL to merge the results of all the sub-queries, and use values in

How to select an unaliased numeric literal from a sub-select

南笙酒味 提交于 2019-12-24 09:47:41
问题 I'm wondering if there is a general SQL syntax allowing for selecting unaliased numeric literals from sub-selects: -- Seems to work in MySQL / Oracle select table_alias."1" from ( select 1 from dual ) table_alias I know I could alias the fields in the subselect: -- Works everywhere select table_alias.column_alias from ( select 1 column_alias from dual ) table_alias But what if I don't have control over the subselect? Also, some RDBMS allow to provide both table AND column aliases when

Means to UPDATE WHERE Value is IN Subquery that has GROUP BY so no Race-Condition Issue(s)?

∥☆過路亽.° 提交于 2019-12-24 09:25:22
问题 Perhaps it's my naiveté, perhaps my paranoia, but I think I'm looking for a solution to a race-condition issue that seems like it should be so common there'd be floods of solutions and I'd've found one by now... but I haven't. The simplistic scenario is I have a process that's supposed to grab any records where there are more than one of a certain type. I'd like to make the system/process(es) thread-/multiprocessing-/reentrant-/buzzword-of-the-day-safe; if the same process gets started and