Using: Django==2.2.24, Python=3.6, PostgreSQL is underlying DB Working with Django ORM, I can easily make all sort of queries, but I started using Metabase, and my SQL might be a bit rusty. The problem: I am trying to get a count of the items in a list, under a key in a dictionary, stored as a JSONField: Exam…
Tag: sql
using FETCH clause is not allowed in mysql .what alternative to be used instead
hi I have 2 tables want to use aggregation and having cluse. can u plz check my query? does not work Answer The nested aggregation MAX(SUM(registration.RegFeeAmntPaid)) is the problem: Nested aggregations are not allowed in SQL: After the first aggregation, there is only one value. Thus, aggregating again doe…
SQL Insert into duplicates
My code is as follows: I should explain the SUM(), there are differing dates on schedule such as I want to get all the “count” of “serviceId” beyond today hence the ‘date >= GETDATE()’ Basically I want the table to look like so: I am able to get the values but I get them…
how to using BETWEEN in CASE
so I want to make a case where if between the year of acceptance and the current year (sysdate) it is 1 to 5 it will be rank 1 and 6 to 10 rank 2 I using the code like this But error it say ‘missing keyword’ in the when between 1 and 5 where EMPLOYEES table contains EMPLOYEE_ID,FIRST_NAME,HIRE_DAT…
How to make a query that filters out only back to back values that do not have any other values in-between?
Write a query that returns all urls involved in a “bounce.” A url X is involved in a bounce if a single user navigates from a page Y to page X, then immediately returns to page Y while visiting no other pages in between. That is, you’ll want to find two visits X->Y (on date d1) and Y->…
Translate Oracle query into pandas dataframe handling
I have the below dataframe: PARAM1 PARAM2 VALUE A X TUE, WED A Y NO B X MON, WED B Y YES I would like a pythonic way of obtaining the distinct values of param1 that satisfy EITHER of these conditions: Their corresponding param2 = ‘X’ contains the string ‘MON’ Their corresponding param2…
Get customer name from table in PostgreSQL
Using this query, we get partner details who have a test today. The customer name is present in another table res_partner: I have tried following code: But I got an error ERROR: column rs.id does not exist LINE 1: …t join (select partner_id from parking_test)pl on rs.id=pl.i… res_partner table: pa…
How to make a query that filter out two AND conditions on same column
Write a query that returns all pages that have been visited by at least one child (demo=’child’) and ALSO has been visited by at least one person aged 18-25 (demo=’18-25′). Your query should return a set of urls. I am not sure how to write a query that filters out results based on Two …
How to convert SQL statement to Power BI DAX?
I have no idea how to recreate the following code from SQL to DAX in Power BI: Or perhaps there is a way to operate on SQL commands in Power BI with imported and filtered tables? I want to do the SQL query on the already sliced data in Power BI. Thank you in advance 🙂 Answer You can achieve
SQL MAX on primary key, is filter condition unncessary if it is already indexed?
id is the primary key. Is date(created_at) = ‘2021-11-05′ and time(created_at) > TIME(’04:00:00’) filter condition unnecessary for Max function since studenthistory is already indexed on class_id and student_id? The only reason I added that datetime filter is because this table will…