Skip to content
Advertisement

SQL – combined SELECT queries and getting a % output

I am using SQLiteStudio and I am trying to run the following query. However, it isn’t returning a value. Can anyone help, please?

I have been asked to provide some of the data. Below I have included how I created my 3 tables and then some sample data for each section. Hopefully, this is enough but feel free to ask for more. These are the 3 tables I have created

Data for the method table

Data for the location table – only included 3 locations.

Data for the record table, it is very pland but I’ve varied the location.

Thanks

Advertisement

Answer

Actually you had just a few syntax errors and correcting them plus adding something like * 1.0 to count() would do what you want (otherwise count() results are integer and in SQL server integer / integer would yield an integer which is 0 in your case).

This is your code, slightly modified to work:

(I agree with preventing old style joins etc but was not the problem here). You could make it a little better:

While the above code works, I think there is a better and cleaner way:

You can also check what is really going on there with adding those fields:

And here is DBFiddle demo using your example data

EDIT: And this is for YAXIS >= 0 and YAXIS < 0 as in your comment:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement