Created
April 6, 2016 10:02
-
-
Save hollodk/b7dc4170c7be1a76a96991bb12d76b1c to your computer and use it in GitHub Desktop.
Some priority stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> select * from product; select * from category; select * from tag; select * from product_tag; | |
+----+----------+-------------+ | |
| id | name | category_id | | |
+----+----------+-------------+ | |
| 1 | shampoo | 1 | | |
| 2 | skocreme | 1 | | |
| 3 | vase | 2 | | |
+----+----------+-------------+ | |
3 rows in set (0.01 sec) | |
+----+----------+ | |
| id | name | | |
+----+----------+ | |
| 1 | mad | | |
| 2 | beverage | | |
+----+----------+ | |
2 rows in set (0.00 sec) | |
+----+------+ | |
| id | name | | |
+----+------+ | |
| 1 | hund | | |
| 2 | kat | | |
| 3 | and | | |
+----+------+ | |
3 rows in set (0.00 sec) | |
+----+------------+--------+ | |
| id | product_id | tag_id | | |
+----+------------+--------+ | |
| 1 | 1 | 1 | | |
| 2 | 1 | 2 | | |
| 3 | 1 | 3 | | |
| 4 | 2 | 3 | | |
| 5 | 2 | 2 | | |
+----+------------+--------+ | |
5 rows in set (0.00 sec) | |
mysql> select pt.product_id, count(*) cnt from product_tag pt left join product p on pt.product_id=p.id group by pt.product_id order by cnt desc; | |
+------------+-----+ | |
| product_id | cnt | | |
+------------+-----+ | |
| 1 | 3 | | |
| 2 | 2 | | |
+------------+-----+ | |
2 rows in set (0.01 sec) | |
mysql> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment