company | email | phone | website | address Amar CO LLC | amar@gmail.com | 123 | NULL | India Amar CO | amar@gmail.com | NULL | NULL | IND Stacks CO | stack@gmil.com | 910 | stacks.com | United …
Tag: sql
Order by 6 digit to 7 digit value then from lowest to highest
This code attempts to sort my values by number of digits, from 6 to 7, then from lowest to highest numerically. I have sets of data in my table and I always get: ID 992425 992199 1001111 I expect result ID 992199 992425 1001111 How to sort by number of digits, from 6 to 7, then ID from lowest to
What could cause MySQL to intermittently fail to return a row?
I have a MySQL database that I am running very simple queries against as part of a webapp. I have received reports from users starting today that they got an error saying that their account doesn’t …
SQL execute block using update
I am trying to perform an execute block using an update. However I am getting an error. The SQL shown here is similar to the real problem, but the update is much more complex. I need to use every declared cust_id into the update block. How can I accomplish that? Answer you cannot use do begin after our update…
Merge values in a column (B) based on common values in column (A) in SQL table
Question: Using SQL, how would you Merge values in a column (B) based on common values in column (A)? Table Structure: I have a SQL table (shown below), where Column A has ID’s and Column B contains Text related to ID’s and Column C contains Rank Order (the order in which text should be should be …
SQL – An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause
If you see the picture below, I only want to see those categories where the average revenue is greater than the overall average. The query that I’m using is below. The very last line is causing the issue. The error that I’m getting is: An aggregate may not appear in the WHERE clause unless it is i…
Categorizing a sub-expression within an expression
Let’s say I have the following select_expr: Ignoring the fact that this query doesn’t make sense, I’m curious how the second select_expr would be categorized: I suppose all three items can be called ‘operands’ and the second two can be called ‘sub-selects’, but is the…
Making cumulative sum with ids and dates in MySQL
Imagine I have this: id transactiondate transactiontag clientid transactionvalue 1 2020-12-28 pizza 0 29.99 2 2020-12-29 payment 0 -39.99 3 2020-12-28 cheese 0 -109.99 4 2020-12-28 cheese 0 -109.99 5 2020-12-28 pizza 1 -19.99 6 2020-12-28 cheese 1 -18.99 7 2020-12-28 salary 1 58.99 8 2020-12-29 salary 1 38.99…
insert same record multiple times based on the given count
I want to insert ABC thrice, EDC four times, FDC twice in a table using single SQL, is it possible? The output of the query should insert into the following table with the following entries. Thanks Answer You would typically use a recursive query: Here is a demo; the syntax works in both Postgres and MySQL 8.…
MySQL – #1064 – Something is wrong in your syntax ‘LIMIT 0, 25’
Server: MariaDB, version 10.4.17 Query: Error in phpMyAdmin: Error in MySQL Workbench: All right so MariaDB decided to modify my query throw error that shouldn’t be thrown Let’s find out what is wrong with select something from (select 1, 2 as something) limit 123: I restarted the server and this …