1

please help mee, can you tell me way ?

$totalah = Sah::find()
      ->select('mhs, SUM(IF(status_kehadiran = 1,status_kehadiran , 0))AS K3211335')
      ->where([
           'kode_mk'=> 'K3211335'
      ])
      ->groupBy('mhs')
      ->all();

 echo "<pre/>"; print_r($totalah);
 die;

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS K3211335 FROM sah WHERE kode_mk='K3211335' GROUP BY mhs' at line 1 The SQL being executed was: SELECT mhs, SUM(IF(status_kehadiran = 1, status_kehadiran, 0))ASASK3211335FROMsimak_absen_harianWHEREkode_mk='K3211335' GROUP BY mhs`

0

2 Answers 2

1

For multiple data in select you can use array. You also need a space before AS:

 $totalah = Sah::find()
  ->select(['mhs', 'SUM(IF(status_kehadiran = 1,status_kehadiran , 0)) AS K3211335'])
  ->where([
       'kode_mk'=> 'K3211335'
  ])
  ->groupBy('mhs')
  ->all();
Sign up to request clarification or add additional context in comments.

Comments

0

If I undestand you purpose, you sum status_kehadiran when status_kehadiran = 1, why you don't just SUM status_kehadiran where status_kehadiran = 1

$totalah = Sah::find()
  ->select(['mhs', 'SUM(status_kehadiran) AS K3211335'])
  ->where([
       'kode_mk'=> 'K3211335',
       'status_kehadiran' => 1
  ])
  ->groupBy('mhs')
  ->all();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.