subquery

How to use MAX() on a subquery result?

放肆的年华 提交于 2020-08-21 08:58:54
问题 I am new to Oracle and the SQL world. I have a slight issue with a query that I cannot figure out for the life of me, I have spent a few hours trying different approaches and I cannot get the result I expect. So heres my query: SELECT * from(Select membership.mem_desc,membership.mem_max_rentals,membership_history.mem_type, count(membership_history.MEM_TYPE) as membership_count from membership_history JOIN membership ON membership.mem_type = membership_history.mem_type group by (membership

Why am I getting error 1054 for this query ? Is there a more efficient way to write this query?

夙愿已清 提交于 2020-07-23 06:45:30
问题 I am working with the sakila database and I need to write a query to find out all the films that are available in the country Canada. SELECT FILM_ID AS Film_id, TITLE AS Title FROM FILM WHERE COUNTRY IN ( SELECT COUNTRY FROM COUNTRY INNER JOIN CITY USING (COUNTRY_ID) INNER JOIN ADDRESS USING (CITY_ID) INNER JOIN STORE USING (ADDRESS_ID) INNER JOIN INVENTORY USING (STORE_ID) INNER JOIN FILM USING (FILM_ID) WHERE COUNTRY = 'Canada') ORDER BY Title ; When I try to run the above-written query, I

Why am I getting error 1054 for this query ? Is there a more efficient way to write this query?

柔情痞子 提交于 2020-07-23 06:44:30
问题 I am working with the sakila database and I need to write a query to find out all the films that are available in the country Canada. SELECT FILM_ID AS Film_id, TITLE AS Title FROM FILM WHERE COUNTRY IN ( SELECT COUNTRY FROM COUNTRY INNER JOIN CITY USING (COUNTRY_ID) INNER JOIN ADDRESS USING (CITY_ID) INNER JOIN STORE USING (ADDRESS_ID) INNER JOIN INVENTORY USING (STORE_ID) INNER JOIN FILM USING (FILM_ID) WHERE COUNTRY = 'Canada') ORDER BY Title ; When I try to run the above-written query, I

How to apply multiple filters to realm database results

青春壹個敷衍的年華 提交于 2020-07-10 07:47:50
问题 I am new to programming & trying to apply filters using UISwitches Currently I have: A realm database returning all the objects A UI that uses Switches to send filters Things Attempted: Subqueries, however I don't know the proper format to write it for realm Goal: Apply multiple filters to realm database results User Interface: Realm Database: class Question: Object { @objc dynamic var neverAttempted: Bool = true @objc dynamic var correct: Int = 0 @objc dynamic var flagged: Bool = false @objc

How to apply multiple filters to realm database results

杀马特。学长 韩版系。学妹 提交于 2020-07-10 07:47:04
问题 I am new to programming & trying to apply filters using UISwitches Currently I have: A realm database returning all the objects A UI that uses Switches to send filters Things Attempted: Subqueries, however I don't know the proper format to write it for realm Goal: Apply multiple filters to realm database results User Interface: Realm Database: class Question: Object { @objc dynamic var neverAttempted: Bool = true @objc dynamic var correct: Int = 0 @objc dynamic var flagged: Bool = false @objc

Django & Postgres - percentile (median) and group by

微笑、不失礼 提交于 2020-05-28 07:27:46
问题 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, default=None) seller_ids = ArrayField(models.IntegerField(), default=list) aux = JSONField(default=dict) Query queryset = ( MyModel.objects.filter(period=25) .annotate(seller_id=Func(F("seller_ids"), function="unnest")) .values("seller_id") .annotate( duration=Cast(KeyTextTransform("duration", "aux"),