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

hitung peringkat rata-rata di server sql

Ini, coba ini:

CONTOH DATA

create table UserDetails(
    Id int,
    ServiceDescription varchar(20),
    Skills varchar(20)
)
create table Review(
    Id int,
    CustomerId int,
    VendorId int,
    Rating int
)

insert into UserDetails values(1, 'Plaster', 'plaster'),(2, 'construction', 'construction'),(3, 'plaster', 'plaster');
insert into Review values(1, 4, 1, 3),(2, 5, 1, 3);

SOLUSI

select
    u.Id as VendorId,
    u.ServiceDescription,
    u.Skills,
    isnull(sum(r.rating)/count(r.rating), 0) as AverageRating
from UserDetails u
left join Review r
    on r.VendorId = u.id
where
    u.ServiceDescription like '%plaster%'
    or u.Skills like '%plaster%'
group by 
    u.Id,
    u.ServiceDescription,
    u.Skills
order by AverageRating desc


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Skema basis data, peningkatan otomatis

  2. Bagaimana cara menghitung total berjalan dalam SQL tanpa menggunakan kursor?

  3. Cara Menemukan Pekerjaan Agen SQL Server di Azure Data Studio

  4. Perbaiki Msg 8116 "Argument data type varchar is invalid for argument 1 of session_context function" di SQL Server

  5. Konversi nilai varchar melebihi kolom int