correlated-subquery

Product with last 4 vendors on transaction date

瘦欲@ 提交于 2019-12-25 03:11:59
问题 Hi I have this sql and have to translate into NHibernate QueryOver SELECT S.Number, S.Description, S.BrandDescription, subquery.vendornumber, subquery.vendorname FROM Stocks.Stock S left join (select vendorNumber, VendorName, POLID, LastTransactionDate from ( SELECT top 4 v.Number vendorNumber, v.Name VendorName, PLL.Id POLID, max(por.TransactionDate) as LastTransactionDate, ROW_NUMBER() OVER(PARTITION BY v.Number ORDER BY max(por.TransactionDate) DESC) AS rk FROM Purchasing

SQL: Counting and Numbering Duplicates - Optimising Correlated Subquery

北城余情 提交于 2019-12-24 14:44:28
问题 In an SQLite database I have one table where I need to count the duplicates across certain columns (i.e. rows where 3 particular columns are the same) and then also number each of these cases (i.e. if there are 2 occurrences of a particular duplicate, they need to be numbered as 1 and 2). I'm finding it a bit difficult to explain in words so I'll use a simplified example below. The data I have is similar to the following (first line is header row, table is referenced in following as

SQL: Counting and Numbering Duplicates - Optimising Correlated Subquery

旧时模样 提交于 2019-12-24 14:32:04
问题 In an SQLite database I have one table where I need to count the duplicates across certain columns (i.e. rows where 3 particular columns are the same) and then also number each of these cases (i.e. if there are 2 occurrences of a particular duplicate, they need to be numbered as 1 and 2). I'm finding it a bit difficult to explain in words so I'll use a simplified example below. The data I have is similar to the following (first line is header row, table is referenced in following as

SQL Server : pivot functionality, need to pivot a table

僤鯓⒐⒋嵵緔 提交于 2019-12-23 08:36:13
问题 I have data in SQL Server in the format below. -ID ID2 status time -1384904453 417 stop 2013-11-19 23:40:43.000 -1384900211 417 start 2013-11-19 22:30:06.000 -1384822614 417 stop 2013-11-19 00:56:36.000 -1384813810 417 start 2013-11-18 22:30:06.000 -1384561199 417 stop 2013-11-16 00:19:45.000 -1384554623 417 start 2013-11-15 22:30:06.000 -1384475231 417 stop 2013-11-15 00:26:58.000 -1384468224 417 start 2013-11-14 22:30:06.000 -1384388181 417 stop 2013-11-14 00:16:20.000 -1384381807 417 start

Is it a slow query? Can it be improved?

守給你的承諾、 提交于 2019-12-22 05:57:54
问题 I was going through SQLZOO "SELECT within SELECT tutorial" and here's one of the queries that did the job (task 7 ) world(name, continent, area, population, gdp) SELECT w1.name, w1.continent, w1.population FROM world w1 WHERE 25000000 >= ALL(SELECT w2.population FROM world w2 WHERE w2.continent=w1.continent) My questions are about effectiveness of such query. The sub-query will run for each row (country) of the main query and thus repeatedly re-populating the ALL list for a given continent.

Is it possible to create a correlated subquery in LINQ?

做~自己de王妃 提交于 2019-12-21 20:18:13
问题 I'd like to create a LINQ query that returns the sum of all quantities for a given productnumber for a parent account and all it's child accounts. I have a table of products by account number in which each row also contains a qty and the parent account number: PartNumber AccountNumber ParentAccountNumber Qty ---------- ------------- ------------------- --- 1000000390 27113 27173 2 1000000390 27516 27173 1 1000000390 00113 27173 0 1000000390 27748 27173 5 SELECT * FROM Inventory WHERE

Is this a valid correlated sub query with joins?

折月煮酒 提交于 2019-12-20 06:14:02
问题 So I have a table Car(Car_id, Value, Make) , another table Person(Person_id, Name) and a third table linking the two together PerCar(Car_id, Person_id) . So I have this correlated subquery: SELECT MAKE, VALUE FROM CAR WHERE VALUE > (SELECT AVG(VALUE) FROM CAR C WHERE C.CAR_ID = CAR_ID); So if I wanted to display the person's name also, is this also valid correlated sub query: SELECT Car.Make, Car.Value, Person.Name FROM PerCar NATURAL JOIN Car NATURAL JOIN Person where Car.Value > (SELECT AVG

SQL Delete clears the table instead of erroring

巧了我就是萌 提交于 2019-12-19 07:54:31
问题 I have a piece of SQL which (you would think) wouldn't compile, but which instead deletes all rows from the target table. Consider this setup: create table TableA (ColumnA varchar(200)); create table TableB (ColumnB varchar(200)); insert TableA values ('A'),('B'),('C'); insert TableB values ('A'); Then the following sql: --Returns all rows from TableA select * from TableA; --Does not error (ColumnA does not exist on TableB) delete TableA where ColumnA in (select ColumnA from TableB) --No Rows

NHibernate QueryOver select entity and aggregates

只谈情不闲聊 提交于 2019-12-18 16:54:55
问题 What I want to do is display a simple grid of data which contains the entity data, and the aggregate data of its children. For example lets use a Order and line items. I want to display the order information, and the count of line items. OrderID, OrderDate, NumOfLineItems Now normally in SQL you can do it many ways. But this is the only way I could think of that might work when translating to NHibernate. SELECT o.OrderID, OrderDate, NumOfLineItems FROM #Orders o INNER JOIN (SELECT o2.OrderID,

Is this a valid correlated sub query with joins?

半腔热情 提交于 2019-12-13 20:17:29
问题 So I have a table Car(Car_id, Value, Make) , another table Person(Person_id, Name) and a third table linking the two together PerCar(Car_id, Person_id) . So I have this correlated subquery: SELECT MAKE, VALUE FROM CAR WHERE VALUE > (SELECT AVG(VALUE) FROM CAR C WHERE C.CAR_ID = CAR_ID); So if I wanted to display the person's name also, is this also valid correlated sub query: SELECT Car.Make, Car.Value, Person.Name FROM PerCar NATURAL JOIN Car NATURAL JOIN Person where Car.Value > (SELECT AVG