SELECT bs.sample_id, bs.item_id, bs.report_id, bs.order_no, bs.order_id, bs.order_business_type, bs.commission_date, bs.customer_name, bs.applicant, bs.phone, bs.receive_user_name, bs.contract_no, bs.special_requirements, bs.report_org_name, bs.report_org_address, bs.sample_name, bs.standard_instrument_name, bs.complete_day, bs.sample_remark AS remark, bs.standard_instrument_id, bs.sample_no, bs.factory_number, bs.item_name, /*bs.item_quantity,*/ bs.inspection_type, bs.mandatory_flag, bs.test_quantity, bs.sample_state, bs.current_site, bs.plan_complete_date, bs.affix, bs.ranges, bs.grade, bs.factory, bs.calibrat_point, bs.apply_dept, bs.specification, bs.final_fee, bs.service_type, CASE WHEN bs.actual_complete_date IS NOT NULL THEN DATEDIFF( bs.plan_complete_date, bs.actual_complete_date ) ELSE datediff( bs.plan_complete_date, now()) END AS surplus_days, bs.report_no, bs.is_report_back, bs.back_reason AS report_back_reason, bs.is_just_certificate, bs.report_state, bs.temper, bs.humidity, bs.test_result, bs.test_date, bs.next_test_date, bs.test_cycle, bs.test_address, bs.generate_time, bs.point_report_id, bs.is_merge, bs.circulation_flag, bs.item_proposal_fee AS proposal_fee, bs.change_price_reason, bs.test_user_name, bs.group_id, bs.group_name, bs.charging_num, bs.other_fee, bs.receivable_fee, bs.affix_quantity, bs.test_org, bs.out_org_order_no, bs.out_org_sample_no, bs.business_user_name, bs.pdf_path, bs.settlement_state, bs.result_describe, bsa.attach_id FROM view_sample_info bs JOIN bus_sample_report bsr ON bs.report_id = bsr.id JOIN bus_sample sa ON bsr.sample_id = sa.id JOIN bus_sample_attr bsa ON sa.id = bsa.id 根据bs.commission_date 进行排序最近的排上面 bs.commission_date
时间: 2024-04-18 07:30:22 浏览: 137
你可以使用 `ORDER BY` 子句根据 `bs.commission_date` 字段进行排序,以将最近的日期排在前面。以下是示例代码:
```sql
SELECT
bs.sample_id,
bs.item_id,
bs.report_id,
bs.order_no,
bs.order_id,
bs.order_business_type,
bs.commission_date,
bs.customer_name,
bs.applicant,
bs.phone,
bs.receive_user_name,
bs.contract_no,
bs.special_requirements,
bs.report_org_name,
bs.report_org_address,
bs.sample_name,
bs.standard_instrument_name,
bs.complete_day,
bs.sample_remark AS remark,
bs.standard_instrument_id,
bs.sample_no,
bs.factory_number,
bs.item_name,
/*bs.item_quantity,*/
bs.inspection_type,
bs.mandatory_flag,
bs.test_quantity,
bs.sample_state,
bs.current_site,
bs.plan_complete_date,
bs.affix,
bs.ranges,
bs.grade,
bs.factory,
bs.calibrat_point,
bs.apply_dept,
bs.specification,
bs.final_fee,
bs.service_type,
CASE
WHEN bs.actual_complete_date IS NOT NULL THEN
DATEDIFF(bs.plan_complete_date, bs.actual_complete_date)
ELSE
DATEDIFF(bs.plan_complete_date, now())
END AS surplus_days,
bs.report_no,
bs.is_report_back,
bs.back_reason AS report_back_reason,
bs.is_just_certificate,
bs.report_state,
bs.temper,
bs.humidity,
bs.test_result,
bs.test_date,
bs.next_test_date,
bs.test_cycle,
bs.test_address,
bs.generate_time,
bs.point_report_id,
bs.is_merge,
bs.circulation_flag,
bs.item_proposal_fee AS proposal_fee,
bs.change_price_reason,
bs.test_user_name,
bs.group_id,
bs.group_name,
bs.charging_num,
bs.other_fee,
bs.receivable_fee,
bs.affix_quantity,
bs.test_org,
bs.out_org_order_no,
bs.out_org_sample_no,
bs.business_user_name,
bs.pdf_path,
bs.settlement_state,
bs.result_describe,
bsa.attach_id
FROM
view_sample_info bs
JOIN bus_sample_report bsr ON bs.report_id = bsr.id
JOIN bus_sample sa ON bsr.sample_id = sa.id
JOIN bus_sample_attr bsa ON sa.id = bsa.id
ORDER BY
bs.commission_date DESC;
```
在上述 SQL 查询中,我们添加了 `ORDER BY` 子句,并使用 `bs.commission_date DESC` 来按照 `bs.commission_date` 字段降序排列结果。这将把最近的日期放在前面。如果你想升序排列,可以使用 `ASC` 关键字,如 `bs.commission_date ASC`。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)