I have a table “MyTable” with an id and two int fields “A” and “B”: MyTable +——-+—–+—–+ | ID | A | B | +——-+—–+—–+ | 99 | 0 | 1 | | …
Tag: sql
Create a stored procedure to populate a table with one row-Yearly and Monthly Averages
I have created a stored procedure to populate a log table. I am having trouble with the syntax for columns H and I. Is there something wrong with my syntax as it relates to monthly and yearly …
Perform a particular ILIKE query on Postgresql
I have a problem with a query in Postgres. I have a column with values such as: id@@@Name1@@@other text@@@other_text@@@other_text@@@CODE@@@other_text### id@@@Name2@@@other text@@@other_text@@@other_text@@@CODE@@@other_text### id@@@Name3@@@other text@@@other_text@@@other_text@@@CODE@@@other_text### Each row ca…
Unexpected result in WHERE clause on AI ID field
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…
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…