In this section, I explain how to find your bank balance using sql query. This questions asked by many interviewer, so please do this practice before go to interview. Here I am created one Transaction table with three fields such as TransactionDate, Description and Amount. Here add primery key to TransactionDate.
You have create a table using below query. And enter some value manually like how I mentioned below.
CREATE TABLE [dbo].[Transaction](
[Transaction Date] [date] NOT NULL,
[Description] [nvarchar](50) NULL,
[Amount] [int] NULL,
CONSTRAINT[PK_Transaction] PRIMARY KEY CLUSTERED
[Transaction Date] ASC
)WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
case when Amount > 0 then Amount end as Deposit,
case when Amount < 0 then ABS(Amount) end as Withdraw,
(select SUM(Amount) from dbo.[Transaction] where[Transaction Date]<= A.[Transaction Date])
from dbo.[Transaction] as A
order by[Transaction Date]
Post your comments / questions
- How to add two numbers in Android Studio? | Source Code
- FindViewByID returns null in android studio -SOLVED
- Saving changes is not permitted in SQL SERVER - [SOLVED]
- Restore of database failed. File cannot be restored over the existing. -[SOLVED]
- One or more projects in the solution were not loaded correctly in Visual Studio 2019 | FIXED
- How to find Laptop's Battery Health?
- SOLVED-Related Field got invalid lookup: icontains error in Django
- How to enable Search Feature in Django admin?