Let’s say that I have a table with 2 columns: name and number. Name is a string which can have one or more words and I would like a new query with select name number but that in the name column it only has the longest word of the original table. Is there a function in SQL that extracts from
Tag: mysql
How to do an arithmetic operation with aliased column in SQL
I have a databse table as like below: Here, received_by and sent_by are two user ID those who are receiving and sending the product respectively. I want to calculate the total amount of each product of a single user by subtracting the sent amount from received amount. My current query looks like below: Here I…
Merging databases – adding rows that not existing in one db to another
I have 2 databases from WordPress website. There was happenned issue and 50% of my posts dissapeared. I have database 1 copy from 03.03.21 And existing database 2 of website from 24.03.21 So in database 1 i have many posts thats was deleted And the database 2 has some new posts that not exist in older databas…
MySql – joining tables and getting updated result when one table is updated
Could you please help with this query? I just have started learning SQL, I cannot see where my mistake is. I have tables : USERS (columns: id, firstname and surname) and POSTS(columns:id, user_id and BODY). I want to have a joined table which would reflect the count of users that have posted at least 2 times.…
Performing a Union on groups of rows without the same columns. Trying to generate empty histogram bins
I am using MySQL. I have a table grades, that looks like so: I have a view that counts how many grades are in each bin, for each class using the following query. This returns: I want to add empty bins to this view, like so: So the bins increment by 5, starting at 40, and stopping at 100. My
how to make cohort analysis in mysql
I have a table called order_star_member: DB Fiddle I want to find users in the month March with transaction >= 700000 and first transaction >= 700000. The user whose transaction is >= 700000 is called star member. My query so far: Explanation: in march 2021, there’s only one ‘star member&…
SQL result from table a but name from table b
My request is quiet simple however I can’t find it (maybe I can’t goolge correctly). I have Table A and Table B Table A: ID length 1 50 2 45 2 20 and Table B ID name 1 apple 2 orange I want …
MySQL Java prepared statement Syntax error
I need to select rows from mysql table based on various criteria, for example Colour= Black, or size= L. The code works without the preparedstatement and the question marks, but whenever I attempt to use the question marks the code does not run. I have read something about typing the question mark like ‘…
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 …
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…