Skip to content

Instantly share code, notes, and snippets.

@corean
Created April 16, 2017 06:41
Show Gist options
  • Select an option

  • Save corean/aa20c14a30bb4cf0655315de4b09bd6b to your computer and use it in GitHub Desktop.

Select an option

Save corean/aa20c14a30bb4cf0655315de4b09bd6b to your computer and use it in GitHub Desktop.
(group by)ML_ID별 Y값 갯수, N값 갯수, P값 갯수
$query = Plan::with('movie')
->select(
'ML_ID',
DB::raw('count(ML_ID) as cnt'),
DB::raw("count(if(PLAN_STAT = 'Y',PLAN_STAT, null)) as Y"),
DB::raw("count(if(PLAN_STAT = 'N',PLAN_STAT, null)) as N"),
DB::raw("count(if(PLAN_STAT = 'P',PLAN_STAT, null)) as P")
)
->groupby('ML_ID')
->havingRaw('count(ML_ID)>0 AND ML_ID != ""')
->orderby('ML_ID', 'desc');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment