I am trying to join two tables, people and sales, and displaying results based on a where condition which should be used to join the tables. My current attempt is showing only one result but I want all the rows in the people to be shown regardless of whether they have a record in the sales table, if they have
Remove zero amount in a query
I have a table finalData with the following columns and data I am creating mysql query to display the income and expenses of Singapore per Area, but I have to exclude areas that has zero amount. Here’s the code I tried: Output should be like this Any help would be appreciated. Thanks Answer This logic would be simpler phrased with
SQL: Retrieve missing values from superset
I have a table like this: I want to return a table with all the ratings possible. In this case 1 to 5. So my resulting table will be: I have tried using something like: but this does not work. Can you please suggest a solution for this? Answer You can cross join the list of distinct devices with numbers
Keep a foreign key NULL if info is easily determine?
I have the following tables: An image can have a country (or not) or a place (or not). Let’s say that I have a record in the country table: And places in the place table: I want to tag an image with the country Spain and a place Barcelona In the image table, should I enter the country_id and the
How I can select random amount of rows based on varios criterias?
I have a table that has 3 main categories: age, city and gender. The gender column is boolean. The age category is in the following range: [’18-25′,’26-35′,’36-45′,’46-55′,’56-65′,’66-75′,’75+’] The …
How to fetch all data without the “out of range” SQL Exception?
I’m extracting data from a database, and I’m getting com.microsoft.sqlserver.jdbc.SQLServerException: The index 15 is out of range. during RunTime. My connection class is executed as the following: While I understand why it’s happening, in this while loop: I don’t quite understand how to fetch the data without it, since there are 14 fields, and an arbitrary number of rows in
Division of 2 values in mysql
Hello I’m a newbie in SQL. I have a table of workers and I want to calculate the avg num of female workers. I want to divide 2 tables that I create, but when I do the division the value of the new …
Select longest duration time (data type field) and client name SQL
I have these tables: CREATE TABLE Client ( client_id NUMBER(10) NOT NULL PRIMARY KEY, name VARCHAR(50) NOT NULL, address VARCHAR(50) NOT NULL ); CREATE TABLE Projects ( project_id …
Postres SQL select with GROUP BY and COUNT
i have this SQL select SELECT t.debtor_account, COUNT(t.debtor_account) FROM transaction t GROUP BY t.debtor_account HAVING COUNT(t.debtor_account) > 2; which work, but i need select all from …
Which SQL function I should use to repeat existing row values for a new column
I have a table with 2 column studentID and StudentName and department. StudenID StudentName Department 1 john IT 2 Michael Finance 3 Josh chemical I …