The column OTI in traits_general comprises of string values. What I am attempting to do here is to select, in descending order by the amount of zeros in each string, each OTI value. For example: In this instance, if we had the strings, 03001, 22321, 00002, 30203, and 11102, then I would want for it to be orde…
Tag: mysql
select conditionally with conditional joins in mysql
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 w…
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
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 on value change
I have a table that looks like this in a MySQL database: I would like to select all lines where the Batch_Num is different from the previous value including the first one: Is there a keyword maybe to access the previous line to compare the to the current line? Or some other way to compare a line to the line
How can I get SUM result as an alias in MYSQL?
The code I wrote above results show like this. I want to know how to Sum numbers in the column ‘COUNTSVCE’. The column ‘COUNTSVCE’ is an alias of count(SVCE_DOMAIN). Rollup function might be a good solution but I can’t use it in my JAVA query so I get the result as alias. Thank y…
Mysql subquery in where clause that returns comma separated value
I’m not really good at subqueries, here’s the sample tables that I have. table customers ===================== id | name | order_ids 1 | John | 1,2 table orders ===================== id | name 1 …
Can you use ORDER BY (column) LIMIT with a secondary column?
I want to find out the Top 10 rented movies in the sakila db. It must be sorted DESC after total_rentals and secondary after film title. My solution looks like this and works so far without the film …
Show sales per employee (staff) and year in sakila db?
I’m kind of stuck on an excercise concerning the sakila db. I want to show sales per employee (staff) and year in mySQL and I’m failing at using the staff_id’s correctly. This is all I have so far: …