SQL Technique - Using Function Count() with condition Case in select statement

preview_player
Показать описание
Source Code:
1- Create Table
CREATE TABLE [dbo].[SaleInvoice](
[InvoiceNo] [varchar](50) NULL,
[Dates] [datetime] NULL,
[ItemCode] [varchar](50) NULL,
[Qty] [int] NULL,
[Price] [numeric](18, 2) NULL,
[Amount] AS ([Qty]*[Price]),
[Promotion] [varchar](50) NULL
) ON [PRIMARY]
GO
2- Insert Data into Table by yourself
3- Write this script
select ItemCode,Count(case when Promotion='Yes' then 1 end) as num_promotion from SaleInvoice
group by ItemCode
Рекомендации по теме
Комментарии
Автор

great! you've helped me, thank you so much!!!!

poet