subquery Questions
3
Solved
I need to calculate period medians per seller ID (see simplyfied model below). The problem is I am unable to construct the ORM query.
Model
class MyModel:
period = models.IntegerField(null=True,...
Ommiad asked 10/1, 2020 at 18:11
4
Solved
It is possible to generate the following query using CI's query builder methods?
SELECT name
FROM table1 t1
JOIN
(SELECT ID FROM table2 ORDER BY id LIMIT 5) t2
ON t2.id=t1.t2_id
WHERE t1.id&...
Priestley asked 10/1, 2013 at 5:29
6
I have a query like this, I want to use this query in Codeigniter.
SELECT sum(price)
FROM (SELECT price
FROM items
ORDER BY price DESC
LIMIT 3
) AS subquery;
I have did
$this->db->select...
Languish asked 2/4, 2015 at 9:44
4
The naive way of doing this that comes to mind would be:
SELECT name, lev FROM
(SELECT name, levenshtein(name, *parameter*) as lev FROM my_table)
WHERE
lev = (SELECT MIN(lev) FROM
(SELECT name, ...
Asquint asked 10/9, 2010 at 18:20
3
Solved
Is is possible to accomplish the equivalent of a LEFT JOIN with subselect where multiple columns are required.
Here's what I mean.
SELECT m.*, (SELECT * FROM model WHERE id = m.id LIMIT 1) AS mode...
Stile asked 17/3, 2010 at 23:36
3
Solved
I have this query I have written in PostgreSQL that returns an error saying:
[Err] ERROR:
LINE 3: FROM (SELECT DISTINCT (identifiant) AS made_only_recharge
This is the whole query:
SELECT CO...
Nonscheduled asked 8/2, 2013 at 6:50
18
Solved
I have a table story_category in my database with corrupt entries. The next query returns the corrupt entries:
SELECT *
FROM story_category
WHERE category_id NOT IN (
SELECT DISTINCT category.i...
Callow asked 5/9, 2008 at 10:3
5
Solved
How can i make this work?
SELECT *
FROM item
WHERE item_name LIKE '%'
|| (SELECT equipment_type
FROM equipment_type
GROUP BY equipment_type)
|| '%'
The inner sub query returns a list ...
5
Solved
I am trying to copy the corresponding graduation_date values from the graduation_term table into the rows in the user_education_mba_school table that have the matching graduation_term_id. Here is m...
Stanton asked 29/6, 2012 at 0:24
1
On AWS Athena, I am trying to reuse computed data using a WITH clause, e.g.
WITH temp_table AS (...)
SELECT ...
FROM temp_table t0, temp_table t1, temp_table t2
WHERE ...
If the query is fast, t...
Seriocomic asked 21/2, 2019 at 21:13
3
Solved
I used the following query with MySQL 5.5 (or previous versions) for years without any problems:
SELECT t2.Code from (select Country.Code from Country order by Country.Code desc ) AS t2;
The ord...
Cundiff asked 15/10, 2014 at 0:18
28
Solved
I have a table with the following fields:
id (Unique)
url (Unique)
title
company
site_id
Now, I need to remove rows having same title, company and site_id. One way to do it will be using the follo...
Embrocation asked 22/7, 2010 at 18:3
22
Solved
What is the most efficient way to get prime numbers from 2 to 1000 via SQL in MongoDB/MySQL/CockroachDB?
My query in Oracle:
WITH NUM AS (
SELECT LEVEL N
FROM DUAL CONNECT BY LEVEL <= 1...
8
Solved
I have this table in a postgres 8.4 database:
CREATE TABLE public.dummy
(
address_id SERIAL,
addr1 character(40),
addr2 character(40),
city character(25),
state character(2),
zip character(5)...
Groundsel asked 6/6, 2011 at 18:49
2
Solved
I have three tables:
table "package"
-----------------------------------------------------
package_id int(10) primary key, auto-increment
package_name varchar(255)
price decimal(10,2)
ta...
Tentative asked 14/10, 2010 at 17:12
2
Solved
How can one get records with highest/smallest per group?
Former title of this question was "using rank (@Rank := @Rank + 1) in complex query with subqueries - will it work?" because I was...
Bodywork asked 5/1, 2012 at 20:4
4
Solved
Basically, I am trying the following:
SELECT m.col1, SUM(SELECT col5 FROM table WHERE col2 = m.col1)
FROM table AS m
This doesn't seem to work. Is there any solution?
Constrictor asked 6/1, 2012 at 11:20
20
Solved
Interactive exercise 9 Difficult Questions That Utilize Techniques Not Covered In Prior Sections at https://sqlzoo.net:
Find the continents where all countries have a population <= 25000000. Th...
26
Solved
Can anyone help me with the following:
Some countries have populations more
than three times that of any of their
neighbours (in the same region). Give
the countries and regions.
my try:
s...
7
Solved
Is it always a best practice to use -
Select E.Id,D.DeptName from Employee E join Dept D on E.DeptId=D.Id
instead of -
Select Employee.Id,Dept.DeptName from Employee join Dept on Employee.DeptI...
5
Solved
Take the case of two tables: tbl_product and tbl_transaction.
tbl_product lists product details including names and ids while tbl_transaction lists transactions involving the products and includes ...
Dolichocephalic asked 27/7, 2010 at 23:8
4
Solved
I'm trying to get an average for a count on a groupBy by joining with a subquery. Don't know if that the right way to go at all but I couldn't anything about subqueries other than the mysema doc.
...
6
Solved
I need to do a big query, but I only want the latest records.
For a single entry I would probably do something like
SELECT * FROM table WHERE id = ? ORDER BY date DESC LIMIT 1;
But I need to pu...
Gambeson asked 5/11, 2009 at 22:56
3
Solved
Why doesn't the following work?
SELECT name FROM (SELECT name FROM agentinformation)
I guess my understanding of SQL is wrong, because I would have thought this would return the same thing as
...
Antisthenes asked 7/1, 2011 at 20:27
12
Solved
1 Next >
© 2022 - 2024 — McMap. All rights reserved.