duannei1477 2019-05-22 05:08
浏览 42

如何从两列获取唯一的值列表?

I have table named projectlist as below. I would like to get list of cities from each country & list of projects from each city

-Country    City        Project    
-India      Chennai     Project1    
India       Hyderabad   Project2    
India       Delhi       Project3    
India       Mumbai      Project4    
India       Bangalore   Project5    
USA         Shreveport  Project6    
USA         Chicago     Project7    
USA         New York    Project8    
USA         Huston      Project9    
Germany     Berlin      Project10    
Germany     Munich      Project11    
Germany     Framkfurt   Project12    
India       Hyderabad   Project13    
India       Bangalore   Project14    
USA         Shreveport  Project15    
Germany     Berlin      Project16    
Germany     Munich      Project17    

I have the below code in my laravel controller. I know that the below code is a wrong approach, please guide me with sample codes. And I would like to return this value and display in blade view

$data4 = DB::table('loksabha2014')
       ->select(
        DB::raw('alliance as alliance','partyname as partyname'),
        DB::raw('count(*) as number'))
       ->groupBy('alliance')
       ->get();

I would like to display as below in my blade view

Cities List:

India - Chennai, Hyderabad, Delhi, Mumbai, Bangalore    
USA - Shreveport, Chicago, New York, Huston     
Germany - Berlin, Munich, Framkfurt 

Project List:

Chennai - Project1    
Hyderabad - Project2, Project13    
Delhi - Project3    
Bangalore - Project14    
Shreveport - Project6, Project15    
Chicago - Project7    
New York - Project8     
Huston - Project9     
Berlin - Project10, Project16    
Munich - Project11, Project17    
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?