public functions questions(){
$instance = $this->newRelatedInstance(Question::class);
$localKey = $this->getKeyName();
$query = $instance->newQuery()
->join('test_question', 'test_question.question_id', '=', 'questions.id')
->join('tests', 'tests.id', '=', 'test_question.test_id')
->join('lessons', 'lessons.id', '=', 'tests.lesson_id')
->join('modules', 'modules.id', '=', 'lessons.module_id')
return $this->newHasMany(
$query, $this, 'modules.course_id', $localKey
);
}
SELECT materials.id,
materials.title,
materials.author,
materials.description,
types.name AS type,
categories.name AS category
FROM materials
LEFT JOIN categories
ON materials.id_category = categories.id
LEFT JOIN types
ON materials.id_type = types.id
LEFT JOIN tags_to_materials
ON materials.id = tags_to_materials.material_id
LEFT JOIN tags
ON tags.id = tags_to_materials.tag_id
WHERE materials.author LIKE '$str%'
OR materials.title LIKE '$str%'
OR categories.name LIKE '$str%'
OR tags.name LIKE '$str%'
select materials.id,
materials.title,
materials.author,
materials.description,
types.name AS type,
categories.name AS category
FROM materials
LEFT JOIN categories
ON materials.id_category = categories.id
LEFT JOIN types
ON materials.id_type = types.id
LEFT JOIN tags_to_materials
ON materials.id = tags_to_materials.material_id
LEFT JOIN tags
ON tags.id = tags_to_materials.tag_id
where materials.id in (
SELECT materials.id
FROM materials
LEFT JOIN categories
ON materials.id_category = categories.id
LEFT JOIN types
ON materials.id_type = types.id
LEFT JOIN tags_to_materials
ON materials.id = tags_to_materials.material_id
LEFT JOIN tags
ON tags.id = tags_to_materials.tag_id
WHERE materials.author LIKE '$str%'
OR materials.title LIKE '$str%'
OR categories.name LIKE '$str%'
OR tags.name LIKE '$str%' group by materials.id);
class Single
{
public array $data = [];
public static $instance;
PRIVATE function __construct()
{
}
public static function getInstance()
{
if (empty(self::$instance)) {
self::$instance = new Single();
}
return self::$instance;
}
public function __get(string $key)
{
return $this->data[$key]??null;
}
public function __set(string $key, $value)
{
$this->data[$key] = $value;
}
}
class A
{
public static function tryW()
{
Single::getInstance()->some = 1;
}
}
class B
{
public static function tryR()
{
var_dump(Single::getInstance()->some);
}
}
$a = new A();
$a->tryW();
$b = new B();
$b->tryR();
select sum(distance) from (select
ST_Distance_Sphere(
point(points.longtitude, points.latitude),
(select
point(next.longtitude, next.latitude)
from
points as next
where
next.date > points.date
and
next.date between '2022-07-01 00:00:00' and '2022-07-05 00:00:00'
order by date asc limit 1)) as distance
from points
where date between '2022-07-01 00:00:00' and '2022-07-05 00:00:00'
order by date asc) as t;
SELECT user.*
FROM user
join
(
SELECT name, profession, city
FROM user
GROUP BY name, profession, city
HAVING COUNT(*) > 1
) as groupped on
groupped.name = user.name and COALESCE(groupped.profession = user.profession, 1) and COALESCE(groupped.city = user.city, 1)
ORDER BY name;