Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

Permintaan SQL untuk menghitung catatan per bulan

Anda hampir sampai:Cukup tambahkan pengguna ke daftar pilihan:

select [Usr],
  [1] AS January,
  [2] AS February,
  [3] AS March,
  [4] AS April,
  [5] AS May,
  [6] AS June,
  [7] AS July,
  [8] AS August,
  [9] AS September,
  [10] AS October,
  [11] AS November, 
  [12] AS December 
from
(
SELECT MONTH(DateVisit) AS month, [User], [User] as [Usr] FROM UserVisit
) AS t
PIVOT (
COUNT([User])
  FOR month IN([1], [2], [3], [4], [5],[6],[7],[8],[9],[10],[11],[12])
) p


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Di mana Penganalisis Kueri di SQL Server Management Studio 2008 R2?

  2. Pemeran T-SQL versus Konversi

  3. SQL Server - Peningkatan otomatis yang memungkinkan pernyataan UPDATE

  4. Apakah lebih baik menjalankan banyak perintah sql dengan satu koneksi, atau menyambung kembali setiap saat?

  5. SQL Server DI HAPUS Pemicu