|
我在SQL Server中有一个日志表,看起来像这样:' o b6 A" @. P+ t( }+ G/ d+ k
CREATE TABLE [dbo].[RefundProcessLog](
3 _3 D$ ~1 Q, r- l5 d [LogId] [bigint] IDENTITY(1,1) NOT NULL,4 C, F$ l8 S" Q G/ B/ H
[LogDate] [datetime] NOT NULL,
& B Y7 X5 T! S' Q8 W- i [LogType] [varchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
- t* y; h8 n' |+ [6 [3 }9 C [RefundId] [int] NULL,
5 L: z' G9 K( f8 q- W) }9 u [RefundTypeId] [smallint] NULL,
* f9 i8 |; c! Y6 E- D2 Z( C; u [LogMessage] [varchar](1000) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,; q: s: v% g4 q, A
[LoggedBy] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
) ^7 H' m2 R6 h% Z CONSTRAINT [PK_RefundProcessLog] PRIMARY KEY CLUSTERED : h/ V3 q2 |8 q/ C' n' m# G
(
: Q- V, ?, x( _( a4 I- N [LogId] ASC/ x, }* U" z/ K! i: t; d
) ON [PRIMARY]
6 i8 V; E: G8 R' k) ON [PRIMARY]" Q, J6 ?! e& Y2 c2 e: @
GO/ u/ v {- z3 R) \2 x' Y
我想要的是一个结果列表,该列表表示每天处理了多少种不同的退款,并抛出了所有NULL。2 T& q' c! K F r/ Z2 v) ^
我需要编写什么SQL才能产生这些结果?
, q: e6 [0 C4 d0 d! Q" J # T4 ^# x2 D3 ?5 D' W
解决方案:5 X. f% X1 V8 `
2 i7 N4 p; N- a6 W: z
; T' [. u7 r2 o; H+ b# j
# w# s2 C" T3 e, H
我喜欢(MS SQL)中的这种方法:
% t9 _" O Z- D6 QSELECT
( D! C: ?, D- W$ Q# i Convert(char(8), LogDate, 112),
) W0 C2 B/ k7 \( R' ] count(distinct RefundId), A. b& ?. q+ ^+ `
FROM RefundProcessing
8 u F- J2 q8 u/ v1 Y$ K; ?GROUP BY Convert(char(8), LogDate, 112) |
|