SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,668 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
i want to not sum last inserted in table against I_ID column.
I_ID=222 ,have three value 500 ,600 and 400. i have inserted last value 400 against I_ID ,which should not be sum and result will be 1100.
Create TABLE #Tbl_IB_Cus_Libility (Li_ID int,I_ID int,I_Amt int)
Insert into #Tbl_IB_Cus_Libility values (1,222,500)
Insert into #Tbl_IB_Cus_Libility values (2,222,600)
Insert into #Tbl_IB_Cus_Libility values (3,222,400)
Insert into #Tbl_IB_Cus_Libility values (4,225,200)
Here's one option:
SELECT li.I_ID, SUM(I_Amt)
FROM #Tbl_IB_Cus_Libility AS li
WHERE li.Li_ID <> (SELECT MAX(i.Li_id) FROM #Tbl_IB_Cus_Libility AS i WHERE i.I_ID = li.I_ID)
GROUP BY I_ID