php - Sql查询比较mysql中同一个表中不同行的相同字段

标签 php mysql

我试图从“tbl_gig”表中获取记录,同时比较其中的不同行。 enter image description here 我尝试过,但没有成功:

SELECT * FROM tbl_gig as t2 INNER JOIN tbl_gig as t3 
WHERE t2.gig_city=t3.gig_city 
  AND t2.artist_id=t3.artist_id 
  AND t2.partner_id < t3.partner_id 
GROUP BY t2.gig_eventDate;

预期输出:

gig_id   gig_artist_id  gig_partner_id
<小时/>
1        1                1
2/3      1                1/2
4        1                1

请帮忙解决这个问题。

最佳答案

SELECT 
   GROUP_CONCAT(gig_id SEPARATOR '/') as gig_id,
   artist_id ,
   GROUP_CONCAT(partner_id SEPARATOR '/') as partner_id
   FROM tbl_gig 
   GROUP BY artist_id 

关于php - Sql查询比较mysql中同一个表中不同行的相同字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28698379/

相关文章:

php - 如何为竞价网站制作倒计时器

php - PHP 告诉我的错误与我的代码插入 Mysql 表之间的奇怪区别?

php - 在 CodeIgniter 中加载多个库 - PHP

mysql - 按日历周的 SQL 销售报告

php无法连接到mysql

php - 调用正在运行的程序并在 php 中获得响应

php - Sweetalert 对数据库进行删除操作

PHP:过滤特定列的mysql_query结果?

mysql - 存储标有多个类别的项目 - 位掩码?

php - 选择 *,最后(日期时间)