簡體   English   中英

使用最大計算分配給用戶的最多項目

[英]Counting the most amount of items assigned to a user using greatest

我試圖在我的 mysql 數據庫中查詢 5 個單獨的表,並顯示分配給他們的項目數量最多的演員。 表結構如下;

item
itemid | item | description | brand | date | time | path |

actor
actorid | name | actorthumb | bio |

brand
brandid | brandname | description | image |

movie
movieid | title | genre | year | moviethumb | synopsis|

request
requestid | userid | itemid | brandid | movieid | actorid | content | requestdate |

我想我需要將請求、演員和項目表連接在一起,使用 COUNT function 計算分配給演員的項目數量,然后使用 GREATEST 顯示分配給他們的項目數量最多的演員?

The query to join all the tables is 
$query = "SELECT greatest i.*, a.*, b.*, m.*, r.* FROM item AS i, actor AS a, brand AS    b, movie AS m, request AS r
    WHERE r.itemid = i.itemid 
    AND r.actorid = a.actorid
    AND r.brandid = b.brandid
    AND r.movieid = m.movieid";

請確認執行上述操作的最佳方法?

SELECT a.actorid, a.name
    FROM request r
        INNER JOIN actor a
            ON r.actorid = a.actorid
    GROUP BY a.actorid, a.name
    ORDER BY COUNT(DISTINCT r.itemid) DESC
    LIMIT 5
The query to join all the tables is 
$query = "SELECT i.*, a.*, b.*, m.*, r.* FROM item AS i, actor AS a, brand AS    b, movie AS m, request AS r
    WHERE r.itemid = i.itemid 
    AND r.actorid = a.actorid
    AND r.brandid = b.brandid
    AND r.movieid = m.movieid
    ORDER BY count(i.*) DESC";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM