Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

MySQL - Bagaimana cara membatasi satu hasil per ID?

CREATE OR REPLACE VIEW employee_sales_totals AS
    SELECT
        e.*,
        SUM(p.total_sale_value)   AS total_sale_value
    FROM
        Employee e
    INNER JOIN
        Payment  p
            ON p.employee_number = e.employee_number 
    GROUP BY
        e.id  -- This should be the Primary Key / Surrogate Key of the employee table
;

CREATE OR REPLACE VIEW shop_top_employee_by_sales_value AS
    SELECT
        s.storename          AS "Store", 
        e.employee_name      AS "Employee", 
        m.employee_name      AS "Manager", 
        p.total_sale_value   AS "Sales Value" 
    FROM
    (
        SELECT storeid, MAX(total_sale_value) AS total_sale_value
          FROM employee_sales_totals
      GROUP BY storeid
    )
       p
    INNER JOIN
        employee_sales_totals   e
            ON  e.storeid          = p.storeid
            AND e.total_sale_value = p.total_sale_value
    INNER JOIN
        fss_Shop   s 
            ON s.storeid = e.storeid 
    INNER JOIN
        Employee   m
            ON m.employee_number = e.manager_number 
;

Sesuai dengan jawaban atas pertanyaan Anda sebelumnya, jika beberapa karyawan terikat untuk jumlah total penjualan yang sama di toko yang sama, semua karyawan tersebut akan dikembalikan.



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. MYSQL pilih 3 baris terakhir, pesan berdasarkan ASC

  2. SQLSTATE[HY000] [2002] php_network_getaddresses:getaddrinfo gagal:Nama atau layanan tidak diketahui

  3. bagaimana cara membuat bidang terhitung di mysql?

  4. ekstrak mysql tahun dari format tanggal

  5. Cara membuat pemicu di perpustakaan migrasi Codeigniter