I have three models: This is what I want: Feedback model has a result field. If result is true or false, the feedback is closed. If result is nil, the feedback is unclosed. I want to sort from the unit with the highest number of unclosed feedbacks to the unit with the lowest. It should be at the bottom of
Tag: sql
Django, have model to be related to many instances of itself
I have a model: I want it to have a sub_industries field that will hold all of its sub industries, which should be instances of Industry model. I cannot be ManyToMany because each industry has only one parent industry. Answer You can add a ForeignKey to itself with: You can use NULL/None to express that an in…
How to write advance complex SQL Query for below data? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 1 year ago. Improve this question How to write a complex SQL Query? Below information is the old data of user…
INSERT INTO – Subquery returns more than 1 row (PHP/MySQL)
I’m trying to develop a website with PHP and MySQL. Here is my PHP code I tried: $sql = sprintf(“INSERT INTO request_boms SET request_list_id = %d, …
Check whether a number is in a string range
I have a table ID Count Range 1 33 1-100 2 120 101-200 3 155 201-300 The Range is a string that can only have the values 1-100, 101-200, 201-300. I need to write a query that checks whether the count and the range fits, so 155 should pop up. My idea was: but this does not work. Can anyone
Combine two tables with different columns and data
How can I combine two tables with different data and set value for CompanyC to all data in Table 2 even there is no relationship of CompanyC on Table2. And the Result Table would be like: I already tried this and it is working but the problem is since CompanyC has no data on Table 2. The result will be
How to get the latest date time record in an sql query with a where clause?
I have two tables : RO_LAMEL_DATA and RO_MAIN_TABLE. RO_MAIN_TABLE includes all the serial numbers (serial_nr) for the productions which have a record key (record_key). RO_LAMEL_DATA has several records (on the same day) for each record key such as machine status (machine_status) with a date time value (pr_da…
Is there a way to continue on the next row after listagg() runs out of space (>4k)?
I would like to change a table that has a number of values per week, to having all values in one row per week. But when I use listagg() I run out of space. I can’t change the maximum string size (ALTER SYSTEM SET max_string_size=extended SCOPE= SPFILE), and I don’t want to truncate the resulting s…
How I can get limit_exceded value if value is less than or greater than in “limit_exceded” column i would get 1 else 0 in mysql
database table_img for better understanding Pardon me for weak English writing my sql query that i am getting value,low_value,high_value and limit_exceded_. issue is in limit_exceded to not get correct values, it shows all 0. I want to get int 1 in front of those values whose value is less than 40 or greater …
Keep the sum even on days without revenue in cumulative sum when using window function in Presto
So my problem is that I have sales data from, say for the sake of clarity, 3 different products. I will be selling 10 of these a week and I want to visualize them in a cumulative sum. I have been using the following little snippet to get the cumulative sum of the revenue. However, this is not sufficient since