Home > database >  Leftist writers query, has more concerns left right table, table the same information recorded in th
Leftist writers query, has more concerns left right table, table the same information recorded in th

Time:09-17

Table 1, the user table user
Table 2, the user record from_id

 
SELECT * from ` user ` ` u ` LEFT JOIN ` form_id ` ` f ` ON u.i d=f.u ser_id
The WHERE (` f `. ` addtime ` & gt; Time=6 days ago) AND (` f `. ` addtime ` & lt;=3 days ago)
The ORDER BY ` f `. ` addtime ` DESC LIMIT 20;


Demand is 3 days before the screen is no record of users, how to achieve this?

This I realize screen (6 ~ 3 days) before the last time the user record,
But if the user list of () during the last 3 days, also is the () 6 ~ 3 days before the record to the query,

Normal query is to conform to the conditions of the query and shown out,
That or how in 2 () during the last three days in accordance with the condition of cases, the condition 1 (6 ~ 3 days) before all conform to remove?

CodePudding user response:

Can you say the detailed point, best the query results, and you want to query results,

CodePudding user response:

Requirements: 3 days before the screening unrecorded user
 
SELECT
*
The FROM
The USER u
WHERE
U.i d!=ANY (SELECT DISTINCT f.u ser_id FROM form_id f the WHERE f.a ddtime & gt;=DATE_SUB (CURDATE (), the INTERVAL 3 DAY))

CodePudding user response:

Myself has been solved, is looks a bit complicated, do not know can performance is poor, because this table form_id operation record so data is more,
Bother everybody to help me have a look at the

Overall demand is for 6 days in record, but there is no record of users, three days before

Below is a code, simplifies some unnecessary conditions,
 
SELECT
` u `. ` id ` ` f `. ` addtime ` AS ` f_addtime `
The FROM ` user ` ` u ` LEFT JOIN ` form_id ` ` f ` ON f.u ser_id=u.i d and f.t ype='form_id' and
NOT the EXISTS (SELECT 1 FROM form_id ff
WHERE ff. User_id=f.u ser_id AND ff. Type="form_id 'AND ff. Addtime & gt;=3 days before the timestamp)
WHERE ` f `. ` type `='form_id' AND ` f `. ` addtime ` & gt; The timestamp AND ` f=6 days ago `. ` addtime ` & lt;=3 days before the timestamp of the
The ORDER BY ` f `. ` addtime ` DESC LIMIT 20

CodePudding user response:

refer to the second floor cquzxs response:
demand: select three days before there is no record of the user
 
SELECT
*
The FROM
The USER u
WHERE
U.i d!=ANY (SELECT DISTINCT f.u ser_id FROM form_id f the WHERE f.a ddtime & gt;=DATE_SUB (CURDATE (), the INTERVAL 3 DAY))


Thank you, but you can only apply to the user's field, and demand is to have data within 6 days before (this is I didn't express clearly)
  • Related