L
L
Lordao2019-04-10 20:43:01
SQL
Lordao, 2019-04-10 20:43:01

How to implement the search for elements by criteria?

There are three tables - Item , Detail and DetailsItem . Between themselves, they create a many-to-many relationship. How can I implement an Item search for a specific Detail .
For example, there is a hammer. It consists of several parts such as: iron , wood , copper . I need to find this hammer by detail. For example, I drive in parameters such as wood and copper , which will definitely find the desired element, but if I add an additional parameter such as silicone , then this element is discarded.
Also, these parameters may contain other elements that contain iron , wood and copper , but if one of the parameters does not match, then the element should not be displayed in the final selection.

SELECT item.idItem, detail.idDetail, detail.title FROM item 
JOIN details_item ON item.idItem = details_item.idItem 
JOIN detail ON detail.idDetail = details_item .idDetail 
WHERE detail.title in ("Железо","Дерево","Медь")

This query finds items that have these details, but also displays other items that only match 1 of 3.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
V
Vitsliputsli, 2019-04-10
@Lordao

More or less like this:

SELECT item.title FROM (
  SELECT 
        item.idItem
    FROM item 
    JOIN details_item ON item.idItem = details_item.idItem 
    JOIN detail ON detail.idDetail = details_item .idDetail
    GROUP BY item.idItem
    HAVING  sum(CASE 
        WHEN detail.title in ("Железо","Дерево","Медь") 
        THEN 1 
        ELSE 0 END) = 3
) t
JOIN item ON item.idItem = t.idItem

A
Andrey B., 2017-02-10
@Palehin

Keep https://jsfiddle.net/njrjw18k/ make the corners yourself

J
Justin Bieber, 2017-02-10
@JustinBieber

https://habrahabr.ru/post/240819/
and stuff like that

D
Dmitry Belyaev, 2017-02-10
@bingo347


In fact, in the figure, the function x \ u003d a * sin (b * y) We put the origin in the center of the canvas, animate by changing the coefficient b in certain ranges (you need to select experimentally)

S
Stalker_RED, 2017-02-10
@Stalker_RED

It is possible without canvas and without mathematics.
Make up three vertical stripes with gradients. This is the first layer. Make up white triangles - the third layer. And in the second layer, put your wavy line, and move it up or down, in a circle.
Although, maybe I misunderstood what a "smooth oscillation animation" is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question