I have a table which’s name is users in my MySQL database, and I am using this DB with Ruby on Rails application with ORM structure for years. The table has id field and this field is configured as AI (auto-increment), BIGINT. Example of my users table; The problem I am facing is when I execute the foll…
How to fix the error: ValueError: endog and exog matrices are different sizes
I’m trying to write a program in python that uses a query in SQL to collect data and make a regression model. When I try to actually create the model, however, it gives me this error. I’m pretty sure that I know what is going wrong, but I have no idea how to fix it. I’ve tried several things…
Query ORDER with UNION
I have to do punt an “*” in a list of dates, like this: So, with my low knowledge, I created something like this code: where “*” is present in the table Union. But, the command ORDER doesn’t work and I’ve a sort system just by number, like the follow: How can avoid this? Th…
Order By two columns but have one order
This question is sequelize specific but I’d figure if I found a way to do in SQL then I could find a way to do it in sequelize I need for the request to be ordered back by user.fullname which is joined by using include and by mockUser.fullname which is a JSON field. One important thing to keep in mind
Disregard duplicate rows only when these rows are contiguous
I am trying to show only the first occurrence of an activity if this activity occurs multiple times in a row. Thus, in the scenario below, if activity B occurs 3 times in a row, even if it is at different times, I want to only select the first occurrence. If it occurs again AFTER another activity I also want
Split records into buckets based on counts in reference table
This is a simplified version, stripped down to my core problem. I have a ContactData table with millions of rows of data, with each contact record broken up into categories with a ReferenceID. I now have to assign a new UpdatedValue to each contact record, based on counts from the separate NewValues table als…
INSERT INTO … VALUES () when not exists
I have insert: INSERT INTO barrier (barrier_id, usage_id, type_id, currency_id, modified_date, version_nr) VALUES (barrier_seq.nextval, (SELECT usage_id FROM usages …
Count distinct number of customers per fiscal year and display all dates in query result
DB-Fiddle Expected Result: In the above result I want to list all order dates and count the number of customers distinct per fiscal year. The fiscal year starts two months after the calender year and therefore goes from March to February. (e.g. from 2020-03 til 2021-02). For example Customer_01 appears the fi…
Oracle PL/SQL ORA-00904: invalid identifier
I’m trying to declare a string and use it in a select statement but it’s throwing ORA-00904: invalid identifier. DECLARE var_laufi VARCHAR2(20) := ‘JEIV’; BEGIN EXECUTE IMMEDIATE q'[ WITH …
SQL – complex SELECT query to UPDATE
SQL noob here. So i have a table with a lot of products. Some of these products are clothing, meaning i have e.g. six different SKU’s for one product due to different sizes. I now want to set the …