If in the combo_Nations combobox I select a specific Country (the country name is extracted from the “All_Nations” table in the “Nations_name” column), I would like to get the corresponding ID_Nations of the respective selected country (ID_Nations is found in the same table “All_…
Tag: sql
What is the most efficient way to optimize a filter based on parameters on a SQL Server stored procedure?
Right now I have something like: … and so on, so in the end I’ll have I think this is going to work, but it doesn’t seems efficient to me. Is there a way to optimize this process and filter information with multiple parameters, with the option of some of them being null? Answer The most effi…
Split String into rows but keep associated data
I’m not real familiar with Split_String and my searches aren’t turning up anything that I can figure out for my case. What I need to do is split a field into rows each time its delimited but then for each new row created, copy the associated columns with that field to those new rows. How data will…
Get Other Columns based on window function maximum value, Bigquery
How to get the whole row or other column value for the same row for which window function in over clause gave output. For ex. Using the above query I get output as the best value which defined the maximum number above me when order by timestamp. The output of the above column : I calculated the best value usi…
How to display and link two sql tables?
I’m trying to display genres from a “Genre” Table in SQL to my main table I found a way to do it with one item but I cannot find a way to do it with multiple genres I got an error from this and I don’t know how to fix it. My SQL database: Answer Do a LEFT JOIN for
How to make correct query with complicated conditions?
I have this table: I need to select only that band_names which participant set is not changed all time of its existance(date_join == active_years_begin and (date_left is null or active_years_end is null) or (date_left == active_years_end)) ) for all band participants. So here right answer is The Beatles, Wing…
Postgresql OVER
I have data like: id user index 1 aaa 0 2 bbb 0 3 aaa 1 4 bbb 1 5 aaa 2 6 ccc 0 How to get only the latest index of each user ? Like this result id user index 4 bbb 1 5 aaa 2 6 ccc 0 Answer Looks like a simple DISTINCT ON: This will
Count total day difference in a Pivot SQL
I have data in two tables with dates PAL date and HUB date. I’m looking to show the number of day difference in a table with 6 columns: Client 1day 2days 3days 4days 5days Client will display the clients grouped, 1 Day will display the count of how many datediff of 1. 2 Days will display the count of ho…
How can I optimize/modify this SQL query to have the same results but with better performance?
This SQL query takes time to execute and I don’t know how can I optimize it/or modify it to have the same results with better performance Answer I rewrote my query like this and it’s very fast Correct me, if I am wrong
how to combine queries from one table?
I have a table with dates and some data. How can I display data for each month (January, February, March), and also display the amount for three months, the average for three months and the maximum payment in one request? the result should be like this users date pay balance avg(balance) avg(pay) sum(pay) use…