MySQL组结果

时间:2017-05-04 10:17:29

标签: php mysql

我需要从属性表和类别表中对MySQL结果进行分组 但我无法理解我该怎么做?

我在属性表中有6个类别列

val add: (Int, Int) => Int = _ + _
// or def add(x: Int, y: Int) = x + y
mapped.reduceByKeyAndWindow(add, Seconds(30), Seconds(10))

enter image description here

我需要5个结果,其中cat ID为“41”

谢谢

编辑:

我认为这种方法不适合我,因为我有多类别列

任何人都可以帮助我吗?

SELECT p.*, c.*, p.id id
                  FROM property p
                  JOIN clients c
                    ON p.user_id = c.id
                  LEFT JOIN category ct1
                    ON ct1.id = p.cat1
                  LEFT JOIN category ct2
                    ON ct2.id = p.cat2
                  LEFT JOIN category ct3
                    ON ct3.id = p.cat3
                  LEFT JOIN category ct4
                    ON ct4.id = p.cat4
                  LEFT JOIN category ct5
                    ON ct5.id = p.cat5
                  LEFT JOIN category ct6
                    ON ct6.id = p.cat6
                 WHERE public = '1'
                   AND (p.cat1 = '$cat'
                    OR p.cat2 = '$cat'
                    OR p.cat3 = '$cat'
                    OR p.cat4 = '$cat'
                    OR p.cat5 = '$cat'
                    OR p.cat6 = '$cat')
                 GROUP BY ct1.id, ct2.id, ct3.id, ct4.id, ct5.id, ct6.id
                 ORDER BY p.id DESC

我只得到一个结果,但我需要三个结果,两次ID 99和一次93

enter image description here

谢谢

0 个答案:

没有答案