Hey guys I’m having trouble solving an exercise of SQL: I can’t seem to understand how can I write a query that answers the question in the title based on a purchase database. I tried selecting distinct values per month, but the same customer can make a purchase in different months, so they would …
Tag: sql
Cannot rollback while a subtransaction is active – Error 2D000
I have written a stored procedure that basically loops over an array of fields and performs some manipulation in the db for each iteration. What I want to achieve is, either all the iterations of loops should occur or neither one of them should occur. So let’s say there were 5 elements in the fields arr…
SQL query for duplicate rows based on 2 columns
I have 3 tables movie, rating and reviewer movie has 4 columns movieID, title, year, director rating has 4 columns reviewerID, movieID, stars, ratingDate reviewer has 2 columns reviewerID, name How do I query reviewer who rated the same movie more than 1 time and gave it higher rating on the second review. Th…
SQL query to group consecutive records without destroying the chronological order
I have a table looking like this: GR I VON BIS 1 a 1 2 2 b 2 3 1 c 3 4 1 d 4 5 3 e 5 6 Column “GR” is the info I want to use for grouping. Column “I” holds some none important info. Column “VON” holds originally a date value – for readability I
Get data from same row with MAX()?
[MariaDB 10.4, PHP8.0] How can I rewrite this so it works so it get weight_date from the row with MAX(total_weight) and list it AS highest_weight_date? I have read that we can’t use MAX() among with WHERE? I have tested to rewrite several examples, but I give up and embarrassed show my latest try: I try…
updating data in a table from another table
I have two tables: cart_item product How to correctly update the data in the product table based on the data in the cart_item table? I want to update the quantity of products in the table product. By updating the data in product I will delete all products in the table cart_item. Here is what I would like to g…
PostgreSQL- Round REAL data type (yes, I know numeric exist)
I know REAL data type is not accurate and normally for currency I should use numeric data type. But, I’m asked to do some stuff and one of the conditions is that the data type is real. When I try to do round((….),2) for example, I get that round function does not exist for this data type. My quest…
UninitializedPropertyAccessException in Android Studio using Kotlin
I am a beginner making use of a Roomdatabase. Mostly using it to load in and pass items between tables using simple relationships. For some reason it isn’t properly adding the selected item from the recyclerView adapter to the selectedItem variable. Would appreciate any insight into why this is happenin…
Getting sql data based on row value
I have a table like so: I’m trying to get the last date when the account was active, not counting today. If the id is not present on today’s date, it is not included in the final table. So for the case of id 1, that would be 2022-04-02, and for id 2, it would be 2022-04-01 I can do
Why does this Sql query shows the possible changes but does not implement it?
So, I want to change the prefix of my tables and the following command shows the possible changes that will take place which seems alright but does not seem to implement it. SELECT Concat(‘RENAME TABLE ‘, TABLE_NAME, ‘ TO fan_’, SUBSTRING_INDEX(TABLE_NAME, ‘pc_’,-1), ‘…