Skip to content
Advertisement

Category: Questions

SQL: Return top 1% of values using NTILE function

I have a database with two columns as shown below, ID and COUNT_OF_ACTIONS where I want to return the top 1% of values from the COUNT_OF_ACTIONS – below might not be the best example, but imagine COUNT_OF_ACTIONS going from 0 to 100, so the query should return: 99 and 100 since these counts are >= 99 (top 1% value) I

Add rows accumulated by current month

Is there a way to translate my hard coded SQL script into a dynamic? My problem with this code is that, it still adding the SEPT-DEC it should be zero since we are not yet covered this month My table Expected Result: Starts from JAN then Added the succeeding covered months. Answer You can UNPIVOT your data, use the window

sql selecting unique rows based on a specific column

I have an table like this : I am trying to filter out something like this based on Col1 I am trying to get the all unique rows based on the values in Col1. If I have duplicates in Col1, the first row should be taken. I tried SELECT Col1 FROM tblname GROUP BY Col1 and got unique Col1 but

SQL table.column not working when I use it with full join

I have this SQL query: And it returns the error : “unknown column main.cname in filed list”. while the column certainly exists: seems alright. I tried using aliases but it just made it worse. I’m clueless Answer As coyeb60297 has pointed out, MySQL doesn’t do full outer joins so your query is: and because main has been aliased as full,

Advertisement