The questions asks, “Write a query to display the customer name and the number of payments they have made where the amount on the check is greater than their average payment amount. Order the …
SQL Join : how to show the first table data even the 2nd table condition false
I want to keep show my first table data even the second table condition is false. Table 1 ————————— ID | Name ————————— 1 | Panda 2 | Tiger ————…
How to create unique key base on three field?
I have two foreign keys in table: userId visitorId Also field action I want to add constraints on these three field, that userId + visitorId + action will be unique. How to do that in Workbench, …
SQL: Using SORT to group same values together while mixing different values randomly
Let’s say I have a table Songs(title,songwriter). I want to get a list of songs where songs of the same songwriter appear in one block. So i just sorted: SELECT * FROM Songs ORDER BY songwriter ASC …
How to pull week ending dates and end of month when end of month is mid week
I’m unsure how to proceed with this or what to search for but here goes my attempt at explaining what I’m trying to do! There may be multiple ways to figure this out as well. I am working on a …
Relationships midst two tables?
I have table visitors and table users. Each visitor can be created by only one user and contains field visitors.userId. So, any another user from table users can edit or delete one or more visitors. …
Dynamically name a column based on a WHERE condition
Objective: I am running a query on a weekly basis and would like one of my column to return the ISO_WEEK number with the prefix ‘W’. For example: W1. More specifically, I would like to reproduce the …
SQL : select the oldest record for each distinct element
I apologize for the poor worded title, let me illustrate first Here is the table : select task_id, task_status, date_change, username from logs order by task_id, date_change Results : TASK_ID …
columns in SQL Server
I have a sample table below: Flight Airport Datetime 123 AID_X_YZ 5/5/2018 12:52:00 AM 123 AID_X_YZ–> NRT_X 5/6/2018 5:50:00 AM 123 NRT_X …
Postgres SQL select query syntax
I have this SQL statement, I am getting a syntax error: SELECT * FROM user_table INNER JOIN ( klass_table LEFT JOIN room_table ) Syntax error is vague, it says: You have an error …