嗨我正在設計一個基於審查的數據庫設計。我在這部分有問題 如何檢查兩個用戶是否在社交旅行中對彼此進行了評論?就像我們在工作完成時有一個審查系統,當工作完成時,僱主和自由職業者都可以互相提供評論就像我想在這裏實施,如果僱主沒有給予自由職業者審查,然後他會顯示審查屏幕對自由職業者的工作,反之亦然。 同樣是在這裏對我的應用程序不同的是在我的應用程序是一趟數據庫設計審查系統反對像使用php mysql上班旅行
我有一個行程表,隨身攜帶申請表,項目和回顧在設計表
1- Trip table will have trips of users
2- Registered users can requests items on a trip
3-When the registered user go to the other user created trip page then he can send the request to user against that trip to carry an item for him .
then an entry will be inserted in a carry_request table by sender_id which has requested the item and receiver id the user which has received the requests.
現在我有問題審查表 我如何才能決定哪個用戶給其他用戶審查,哪些還沒有給予審查 我們還將在審查表中對每個carry_request進行審查2項,因爲對1個進位請求我們將有2個審閱來自發件人和來自接收器。
這裏是我的查詢
select i.id as item_id,t.id as trip_id,us.id as sender_user_id,ur.fname as receiver_fname
from carry_requests cr
INNER JOIN users us on cr.sender_id = us.id
INNER JOIN users ur on cr.receiver_id = ur.id
INNER JOIN trips t on cr.trip_id = t.id
INNER JOIN items i on cr.item_id = i.id
where cr.sender_id = 24;
與此查詢我得到的所有記錄針對該用戶所有被罰款,直到我必須發現哪些發送者並沒有給予審查,以接收器或接收器沒有給出審查讓發件人在屏幕上向他們展示留下評論按鈕。 這裏是我的carry_requests表
CREATE TABLE IF NOT EXISTS `carry_requests` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sender_id` int(11) NOT NULL,
`receiver_id` int(11) NOT NULL,
`trip_id` int(11) NOT NULL DEFAULT '0',
`item_id` int(11) NOT NULL,
`date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`is_sender_reviwed` int(11) NOT NULL DEFAULT '0',
`is_receiver_reviwed` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
)
CREATE TABLE `trips` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`uid` INT(11) NOT NULL,
`from_location` VARCHAR(255) NOT NULL,
`to_location` VARCHAR(255) NOT NULL,
`departDTTM` DATE NOT NULL,
PRIMARY KEY (`id`)
)
CREATE TABLE IF NOT EXISTS `items` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`status` int(11) NOT NULL DEFAULT '0',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
審查表具有
CREATE TABLE `reviews` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`trip_id` INT(11) NOT NULL,
`reviewer_id` INT(11) NOT NULL DEFAULT '0', which has given the review
`user_id` INT(11) NOT NULL DEFAULT '0', to whom review was given
`rating` INT(11) NOT NULL DEFAULT '0',
`review` TEXT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
您正在查看的是'LEFT JOIN' – cmorrissey
@cmorrissey如果它們在評論表中是兩行,那麼左連接將返回2條記錄,但我只想要一條記錄 – user5184398
@ user5184398,什麼是reviewer_id和sender_id? – ZeJur