MySQL join four tables and get some kind of SUM result
Tag : mysql , By : taviso
Date : March 29 2020, 07:55 AM
Any of those help I have four tables like this: SELECT c.course_name, p.price_name, SUM(cp.plan_time), SUM(cp.plan_time * p.price_value)
FROM courses c
INNER JOIN pricegroups p ON p.price_id = c.course_price_id
INNER JOIN course_to_plan cpl ON cpl.course_id = c.course_id
INNER JOIN courseplans cp ON cp.plan_id = cpl.plan_id
GROUP BY c.course_name, p.price_name
|
SQL Join: Tables of the same kind
Date : March 29 2020, 07:55 AM
Does that help You don't need a Join, you need to use an UNION query: SELECT title, painterID artistID
FROM Paintings
UNION ALL
SELECT title, sculptorID artistID
FROM Sculptures
|
What kind of JOIN should I use to join these tables?
Date : March 29 2020, 07:55 AM
Does that help Using UNION to bring the light and medium desktops tables together as a single dataset shouldn't give you duplicates unless the tables contain duplicate values in rows accross all columns in your SELECT clauses and you use UNION ALL. If you know your tables have unique values use UNION ALL to give a performance boost. I would combine the two tables in a common table expression (cte) and then join the resultant table with a LEFT OUTER JOIN to your user table which can also be filtered to find entries where there is no match WHERE [user].[UserID] IS NULL, NB, that would return orphaned rows in your desktops tables where the user has been deleted; alternatively drop the left outer join and use WHERE [desktop].[UserID] IS NULL to return only dekstops without assiged users. WITH cte_Desktop AS
(
SELECT
[ID] as [DesktopID],
'Light Desktop' as [DekstopType],
[Model],
[MACAddress],
[UserID]
FROM [dbo].[LightDesktops]
UNION
SELECT
[ID],
'Medium Desktop',
[Model],
[MACAddress],
[UserID]
FROM [dbo].[MediumDesktops]
)
SELECT
[desktop].*
FROM cte_Desktop AS [desktop]
LEFT OUTER JOIN [dbo].[Users] AS [user]
on [user].[UserID] = [desktop].[UserID]
WHERE [user].[UserID] IS NULL
|
Java. Join threads in order of completion and run a kind of a hook after each join
Tag : java , By : Pitmairen
Date : March 29 2020, 07:55 AM
I wish this help you I want to be able to join each thread at once it finished its job. In the code example below main thread will wait as long as each thread will run by their order in the list and only then next thread will be joined. , You should use a CompletableFuture ExecutorService e = Executors.newFixedThreadPool(3);
ExecutorService single = Executors.newSingleThreadExecutor();
List<CompletableFuture<?>> futures = new ArrayList<>();
futures.add(CompletableFuture.runAsync(new Worker(), e).thenRunAsync(this::someHook, single));
futures.add(CompletableFuture.runAsync(new Worker(), e).thenRunAsync(this::someHook, single));
futures.add(CompletableFuture.runAsync(new Worker(), e).thenRunAsync(this::someHook, single));
futures.forEach(f -> f.get()); // try-catch left out for brevity
|
What kind of JOIN statements would retrieve the correct data from 3 tables?
Tag : mysql , By : user183954
Date : March 29 2020, 07:55 AM
This might help you You will use INNER JOINs to join your tables together on their respective/shared keys. Something like the following: SELECT
Students.StudentID,
Students.Studentname,
Courses.CourseName,
CoursesTakes.TargetGrade,
Reports.CurrentGrade,
Reports.ReportNumber
FROM
Students
INNER JOIN CoursesTakes ON Student.StudentID = CoursesTakes.StudentId
INNER JOIN Courses ON CoursesTakes.CourseID = Courses.CoursesID
INNER JION Reports ON CoursesTakes.TakeID = Reports.CourseTakeID
WHERE
Students.StudentID = <yourstudentid>
|