9/14/2
This commit is contained in:
66
lib/models/sql
Normal file
66
lib/models/sql
Normal file
@@ -0,0 +1,66 @@
|
||||
-- to check duplicate CarRegistration
|
||||
SELECT
|
||||
`driverID`,
|
||||
COUNT(*) AS `count`,created_at
|
||||
FROM
|
||||
`CarRegistration`
|
||||
GROUP BY
|
||||
`driverID`
|
||||
HAVING
|
||||
COUNT(*) > 1;
|
||||
--
|
||||
|
||||
|
||||
-- to delete duplicate
|
||||
WITH CTE AS (
|
||||
SELECT
|
||||
MIN(`id`) AS `min_id`
|
||||
FROM
|
||||
`CarRegistration`
|
||||
GROUP BY
|
||||
`driverID`
|
||||
)
|
||||
DELETE FROM
|
||||
`CarRegistration`
|
||||
WHERE
|
||||
`id` NOT IN (SELECT `min_id` FROM CTE);
|
||||
|
||||
-- get for employee
|
||||
SELECT
|
||||
d.`maritalStatus` AS NAME,
|
||||
COUNT(*) AS `count`
|
||||
FROM
|
||||
`driver` d
|
||||
WHERE
|
||||
d.`maritalStatus` IN('Maryam', 'Salma', 'Mena') AND DATE(d.created_at) = CURDATE()
|
||||
GROUP BY
|
||||
d.`maritalStatus`
|
||||
ORDER BY
|
||||
COUNT
|
||||
DESC
|
||||
|
||||
|
||||
-- get driver without cars
|
||||
|
||||
SELECT
|
||||
d.id, d.phone
|
||||
FROM
|
||||
`driver` d
|
||||
WHERE
|
||||
d.id NOT IN (SELECT driverID FROM CarRegistration);
|
||||
|
||||
|
||||
-- car without drivers
|
||||
|
||||
SELECT
|
||||
cr.created_at, cr.driverID
|
||||
FROM
|
||||
`CarRegistration` cr
|
||||
WHERE
|
||||
cr.driverID NOT IN (SELECT id FROM driver);
|
||||
|
||||
|
||||
|
||||
----- driver
|
||||
SELECT phone,email,name_arabic,national_number FROM `driver` WHERE national_number ='29209290106392'
|
||||
ORDER BY `driver`.`created_at` DESC
|
||||
Reference in New Issue
Block a user