subquery

Subquery with invalid identifier error in sql

大憨熊 提交于 2020-01-06 15:47:31
问题 want to select tour date and site names in advance of total cost is more than 230 and that tour has more than 7 persons. the complete code is below, the first part of union works. SELECT tour_date AS "Departure Date", site_name "Site Name" FROM partres, reservation, tour, site WHERE partres.res_id = reservation.res_id AND reservation.tour_id = tour.tour_id AND tour.site_id = site.site_id GROUP BY tour_date, site_name HAVING COUNT(part_id) > 7 UNION SELECT tour_date AS "Departure Date", site

selecting limited subquery data with SPARQL 1.1

岁酱吖の 提交于 2020-01-06 09:47:02
问题 I'm trying to get something done, but I got performance issues. I got stores, and products. The products are linked to the stores via :inStore predicate. The main purpose here is to get 5 products from each matched store with total limit of 75 products. The order should be the closest ?distance and the highest ?price. Here's my query: SELECT ?store ?productID ?distance ?price { { SELECT ?store ?distance { ?store omgeo:nearby(51.5125591000 -0.1248754000 '100km') . ?store geo-pos:lat ?latBase .

selecting limited subquery data with SPARQL 1.1

你离开我真会死。 提交于 2020-01-06 09:41:51
问题 I'm trying to get something done, but I got performance issues. I got stores, and products. The products are linked to the stores via :inStore predicate. The main purpose here is to get 5 products from each matched store with total limit of 75 products. The order should be the closest ?distance and the highest ?price. Here's my query: SELECT ?store ?productID ?distance ?price { { SELECT ?store ?distance { ?store omgeo:nearby(51.5125591000 -0.1248754000 '100km') . ?store geo-pos:lat ?latBase .

Multiple MySQL Queries in 1 Function in Model

末鹿安然 提交于 2020-01-06 08:03:58
问题 Is it possible to run 2 MySQL Queries (select AVG and then Update) in a Function ? How to print / echo the current error by using : $this->db->error(); OR $this->db->last_query(); ? My code contain a MySQL Sub Query, is there any wrong syntax? This below code seems like not working. I am trying to get an average value from the first query and then use the query as a field to store (update) to database. Please help.. public function updateReprob(){ $id = $this->input->post('txtId'); return

Query and get all database names and subquery especific tables from all databases

谁都会走 提交于 2020-01-06 07:01:17
问题 I have different databases. I have tables within each database. I would like to know if I can ask how many databases excluding some such as 'schema' 'mysql' I have once know how to perform a subquery asked by a particular table of all the databases resulting from the first question. example. the structure would be db1 -> user-> id,name,imei,telephone,etc.. db2 -> user-> id,nameuser,imei,telephone,etc.. db3 -> user-> id,nameuser,imei,telephone,etc.. .... db1000 -> user-> id,nameuser,imei

Cardinality violation when using a subquery that returns two values

不问归期 提交于 2020-01-06 02:44:07
问题 I have create a sql query that the sketch is like this select * from A where A.id in (select B.id1, B.id2 from B); where the main select returns those values for which A.id coincides with either B.id1 or B.id2. Clearly this solution doesn't work as the cardinality doesn't match in the where clause. How can I overcome this problem? One solution would be to make two sub-queries, one for B.id1 and one for B.id2, but as my sub-query is much longer than in this example I was looking for a more

MYSQL divide results from multiple subqueries with multiple rows

人盡茶涼 提交于 2020-01-06 02:26:07
问题 I have two queries, the first one generating a table like SELECT COUNT(channel) AS messages FROM Chats WHERE message LIKE '%word%' GROUP BY UNIX_TIMESTAMP(time) DIV 3600 +-----+ | 123 | | 127 | | 332 | | 219 | +-----+ and the second one SELECT COUNT(channel) AS messages FROM Chats GROUP BY UNIX_TIMESTAMP(time) DIV 3600 +-----+ | 222 | | 579 | | 590 | | 377 | +-----+ Now I would like to divide all results from the first table by the corresponding value in the second one (results rounded, had

Building a subquery with ARel in Rails3

元气小坏坏 提交于 2020-01-06 02:20:34
问题 I am trying to build this query in ARel: SELECT FLOOR(AVG(num)) FROM ( SELECT COUNT(attendees.id) AS num, meetings.club_id FROM `meetings` INNER JOIN `attendees` ON `attendees`.`meeting_id` = `meetings`.`id` WHERE (`meetings`.club_id = 1) GROUP BY meetings.id) tmp GROUP BY tmp.club_id It returns the average number of attendees per meeting, per club. (a club has many meetings and a meeting has many attendees) So far I have (declared in class Club < ActiveRecord::Base): num_attendees = meetings

Active Record Insert Into

时光毁灭记忆、已成空白 提交于 2020-01-05 10:26:53
问题 I am trying to allow my Rails App some advanced functionality in way of creating relationships. I am running MySQL as the back-end. The query below runs just fine in PHPMyAdmin, but upon attempted execution in rails, it does nothing, no errors and no database writes.... I use active record to create the relationships between Campaign and Location, and then the query below should work to build afterward in campaign_metros table: class CampaignLocation < ActiveRecord::Base belongs_to :campaign

How to optimise a query containing joins and subqueries

狂风中的少年 提交于 2020-01-05 08:51:50
问题 I have inherited the following query and DB structure and I want to optimise it as it is slow. It contains joins and subqueries which I've read isn't a good plan. I've tried various ways to improve it but am getting stuck/lost. If it is good as it is then fine but if there are suggestions for improving it I would be immensely grateful... The query draws data from various tables to produce a report on how many clickthroughs to a supplier's website, telephone number 'reveals' there have been