-1

我的目标是(对于所有要计算的列)

The Number of Invoices Per Date
1 There were a total of 1 invoice(s) on Apr 02, 2012
2 There were a total of 5 invoice(s) on Apr 01, 2012

InvoiceDate 表需要格式化,但我似乎根本无法投射它,当天有多个发票日期必须以某种方式计算:S

SELECT convert(varchar, getdate(), 107) AS InvoiceDate FROM Invoices

以上是我所知道的,但它一遍又一遍地重复相同的日期

4

2 回答 2

2

听起来你想要这个:

select 
  'There were a total of '
  + cast(count(*) as varchar(10)) 
  + ' invoice(s) on '
  + convert(varchar(12), yourDateCol, 107)
from invoices
group by convert(varchar(12), yourDateCol, 107)
于 2012-11-15T14:25:22.257 回答
1

您只需将日期分组:

SELECT COUNT(*) AS Quantity, convert(varchar,YourDateFieldName, 107)
FROM Invoices
GROUP BY convert(varchar,YourDateFieldName, 107)
ORDER BT YourDateFieldName

请注意,在您的示例中,GETDATE()(又名 CURRENT_TIMESTAMP)将始终返回当前时间戳。

于 2012-11-15T14:22:56.060 回答