I’ve got database of flights and I want it to return average of delay, but I want it to filter ‘origin = ‘SFO” after counting average of arr_delay_new. If I use WHERE or HAVING it counts the average with condition origin = ‘SFO’. How to make it count avg first and filter la…
Tag: sql-server
SQL All Categorized Possible Combinations
I recently had a rather interesting problem to solve where I needed to construct a list consisting of a combined selection of one choice from each of an arbitrarily defined set of categories, and an aggregated total of a value associated with each choice. The choices within each category are also arbitrarily …
SQL Server : search among groups based on multiple conditions
I have the following Product table. I’m trying to find the products based on multiple criteria. Here’s my sample data: +———–+————+——————+—————-+—————̵…
SQL View Select Optional
I have a view that the current output something like this The rules are as follows Each group can only have 2 code and always have a default code vs not a default code. IF default code is not null, then always show the row. Regardless if Non default code has value or not If default code is null, then
How to get TOP larger tables in SQL Server 2000 and their sizes
Is there a way via T-SQL to get the larger tables and their respective size in a SQL Server 2000 engine? Answer I think this script works with SQL Server 2000 even if sp_msforeachtable was not documented
Explain more about date range filter is better than function YEAR() and DATE()?
I am reading book T-SQL fundamental – 3rd edition, page 98 by Itzik Ben-Gan. Solution 1: Solution 2: Author said: Apply manipulation to the filtered column, in most case SQL Server can’t use an index efficiently. Therefore, I advice using a range filter instead. Please explain for me. Why date ran…
SQL Sum of Count Values
I have this query and I’d like to get a sum of the count values in the ‘membership count’ column. How can I get the sum of the count values? Answer If you want a last row with the sum then use GROUP BY ROLLUP:
sql find same two columns
i want to find all same a+b’s for that data my result should be * That works like that I can see which ones are like that. But I want to see RAW data. How can I see all data with that having clause ? Because that table have lots of columns and I dont want to group by them.
SQL Query – SQL Server 2014 – Combine Multiple Colums in Select (Lookup?)
I have this current query (more info than really needed to show): The query returns this output: I need to modify this query so that it only shows IBX, Tanks ID (Where Index != 0) and its associated Level. Level 1 goes to Index 1, Level 2 goes to Index 2, and Level 3 goes to Index 3 I’ve tried
How to insert nested JSON array into SQL Server table
I am trying to insert a JSON file into a table using SQL Server’s “OPENJSON WITH (…” syntax). However, this file contains nested arrays, which I do not know how to handle. Here is my JSON file: } …