I checked several questions for a duplicate but I couldn’t find one. I am dealing with three tables, the first “articles”, the second “tags”, and the third “article_tags” …
Use average of values in “where” clause
I want to select the top x value from a query where the average of valid values for a particular field is above 10. Why is this throwing an error? Answer Your code is throwing an error because avg() is an aggregation function and cannot be in the where clause. What you want seem to want is apply: The subquery
How to write SQL query to get the 2nd heaviest animal from each zoo?
Here are the two tables(animal_weight and zoo_directory): I am confused on how to retrieve the 2nd heaviest animal from each zoo. I was thinking using the MAX function or a subquery but I am not …
Counting the number of repeating customer and new customer for every month in sql
I have table Order looks like this: order_number order_created_date order_completed_date order_delivered_date customer_id order_info gmv R074828364 8/2/2020 9:53 8/2/2020 10:09 …
GROUP_CONCAT and JOINS with multiple lookup tables
I have a simple series of joins with a GROUP_CONCAT that need to be performed on a number of tables and lookup tables. Table unit: +———+———–+ | unit_pk | unit_name | +—–…
JOIN multiple tables based on one reference table and count records
I have these following tables: cars: id manufacturer ——————– 1 Nissan 2 Toyota 3 Honda 4 Volkswagen type: id type car_id ————–…
SQL: Include a new column in an index
I have a nonclustered index over two rows in a table, and that includes a number of columns. The index is used by a view and the view has now been updated to include another column. I generally script …
Remove text after a codeword
I have a list of company names that have been sent with their added company numbers. How can I remove these company numbers (of different length) in SQL? “Limited” if in the name needs to be …
replace column with other column if value is ABC*
MYSQL PHPmyAdmin I have a table “photo” I have a column named “column_title” (varchar(300)) and a column named “column_description” (text). The title is sometimes ABC and …
Rolling sum based on date (when dates are missing)
You may be aware of rolling the results of an aggregate over a specific number of preceding rows. I.e.: how many hot dogs did I eat over the last 7 days SELECT HotDogCount, DateKey, …