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

Bagaimana cara menulis Laravel orderBy query?

pertanyaan Anda tidak jelas untuk orderBy . Berdasarkan pertanyaan Anda :

SELECT report_doctor_company_daily_test.test_id, testing_types.testing_name, doctor.first_name, doctor.last_name, SUM( report_doctor_company_daily_test.test_price ) FROM testing_types INNER JOIN report_doctor_company_daily_test ON testing_types.id = report_doctor_company_daily_test.test_id INNER JOIN doctor ON report_doctor_company_daily_test.doctor_id = doctor.id GROUP BY testing_t ypes.id

Jawaban :

$test = ReportDoctorCompanyDailyTestModal::select(
        'report_doctor_company_daily_test.test_id',
        'testing_types.testing_name',
        'doctor.first_name',
        'doctor.last_name',
        DB::raw('SUM(report_doctor_company_daily_test.test_price)')
    )
    ->join('report_doctor_company_daily_test', 'testing_types.id', '=', 'report_doctor_company_daily_test.test_id')
    ->join('doctor', 'report_doctor_company_daily_test.doctor_id', '=', 'doctor.id')
    ->groupBy('testing_types.id');

dd($test->toSql());
 

Hasil :

select 
     `report_doctor_company_daily_test`.`test_id`, 
     `testing_types`.`testing_name`, 
     `doctor`.`first_name`, 
     `doctor`.`last_name`, 
     SUM(report_doctor_company_daily_test.test_price) 

from 
    `testing_types` 

inner join `report_doctor_company_daily_test` 
    on `testing_types`.`id` = `report_doctor_company_daily_test`.`test_id` 

inner join `doctor` 
    on `report_doctor_company_daily_test`.`doctor_id` = `doctor`.`id` 

group by `testing_types`.`id`
 


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. SQL:mengubah baris menjadi kolom di MySQL (pernyataan SELECT)

  2. Campuran collations ilegal MySQL ketika semuanya disusun sama

  3. Pernyataan UPDATE dalam status akhir kueri

  4. MySQL:ERROR 1022 (23000):Tidak dapat menulis; duplikat kunci dalam tabel '#sql-2b8_2'

  5. mengapa kesalahan `tcgetattr` terlihat ketika ssh digunakan untuk membuang file cadangan di server lain?