Home > database >  MySQL custom in the quarter, and the data accumulation
MySQL custom in the quarter, and the data accumulation

Time:01-15

Single table query get out a patient data for at least two stores to buy, do not satisfy all out
Table fields:
Name of pharmacy to buy medicine pharmacy coding time in the name of the drug specifications purchase quantity prescription pharmacy pharmacy provinces city hospital patient number (random) belonging to a pharmacy

Query full table query is as follows:
SELECT
CDD SELLER_CODE AS 'sellerCode,
CDD SELLER_NAME AS 'sellerName,
CDD ORDER_TIME AS 'orderTime,
QUARTER (CDD) ORDER_TIME) AS 'yearQuarter,
CDD MED_NAME AS 'medName,
CDD. SPEC AS 'SPEC',
CDD AMOUNT AS 'AMOUNT',
CDD PROVINCE_NAME AS 'provinceName,
CDD CITY_NAME AS 'cityName,
CDD. At the AS 'at'
CDD PATIENT_CODE AS 'patientCode,
CDD. SELLER_CODE AS 'lastSellerCode'
The FROM
CDD yiyao_b2c. Cmd_desensitization_data

Excuse me each big, how to write:
And each user is the last time the ownership of the pharmacy to buy medicine pharmacy

CodePudding user response:

 
SELECT *
The FROM yiyao_b2c. Cmd_desensitization_data CDD
WHERE the EXISTS (SELECT 1 FROM yiyao_b2c. Cmd_desensitization_data WHERE CDD. Pharmacy coding & lt; & gt; Pharmacy coding AND CDD. Patient number=the patient number)

CodePudding user response:

Thank you very much for bosses
Trouble under the ask you, check out all data belonging to a pharmacy query for the last order sellerCode (store coding)

CodePudding user response:

reference hackers on the second floor in the reply of the sea:

thank you very much for leadersTrouble under the ask you, check out all data belonging to a pharmacy query for the last order sellerCode (store coding)


 
SLECT A. *, b. pharmacy coding AS belonging to A pharmacy _NEW
The FROM yiyao_b2c. Cmd_desensitization_data AS A
The JOIN
(SELECT number, pharmacy code
The FROM yiyao_b2c. Cmd_desensitization_data CDD
WHERE NOT the EXISTS (SELECT 1 FROM yiyao_b2c. Cmd_desensitization_data WHERE CDD. Patient number=the patient number AND buy medicines time & gt; CDD. Buy medicine time)
=belonging pharmacy AND pharmacy coding) AS B ON a. number=b. patient number


CodePudding user response:

reference RINK_1 reply: 3/f
Quote: refer to the second floor hackers in the reply of the sea:

thank you very much for leadersTrouble under the ask you, check out all data belonging to a pharmacy query for the last order sellerCode (store coding)


 
SLECT A. *, b. pharmacy coding AS belonging to A pharmacy _NEW
The FROM yiyao_b2c. Cmd_desensitization_data AS A
The JOIN
(SELECT number, pharmacy code
The FROM yiyao_b2c. Cmd_desensitization_data CDD
WHERE NOT the EXISTS (SELECT 1 FROM yiyao_b2c. Cmd_desensitization_data WHERE CDD. Patient number=the patient number AND buy medicines time & gt; CDD. Buy medicine time)
=belonging pharmacy AND pharmacy coding) AS B ON a. number=b. patient number



 SELECT 
A. *,
B.S ELLER_CODE AS 'newSellerCode'
The FROM
Yiyao_b2c. Cmd_desensitization_data AS A
The JOIN (
SELECT
PATIENT_CODE,
SELLER_CODE
The FROM
CDD yiyao_b2c. Cmd_desensitization_data
WHERE
NOT the EXISTS (SELECT 1 FROM yiyao_b2c. Cmd_desensitization_data WHERE CDD. PATIENT_CODE=PATIENT_CODE AND ORDER_TIME & gt; CDD. ORDER_TIME)

) AS B ON Amy polumbo ATIENT_CODE=p. ATIENT_CODE

Bosses have a problem, such data were found out
  • Related