比较两个表时如何设置最后日期标准?

dwbf0jvd  于 2021-08-09  发布在  Java
关注(0)|答案(0)|浏览(232)

我只想比较医院支付数据中日期的最后一天(2020-06-25)。我该怎么办?
在这个医院的数据表中

id  |    date     |  card_amount_receiced | store_mbrno
1     2020-06-23            10000               234567
2     2020-06-24            20000               234567
3     2020-06-25            30000               234567

在这个noti\u card\u数据表中

id  |    date     |  card_amount_receiced |      mbrNo
5     2020-06-24            10000               234567
7     2020-06-25            20000               234567
11    2020-06-26            30000               234567

在这个结果中

id  |    date     |         amount         |   result       | card_check
1     2020-06-23            10000                1               N
2     2020-06-24            20000                1               N
3     2020-06-25            30000                1               N

在我的询问中

SELECT id, chart_num, MIN(DATE) AS DATE, amount, (COUNT(*) = 2) AS result, card_check, division
FROM ((
SELECT id,
hpd.chart_num AS chart_num,
hpd.chart_name AS chart_name, 
NULL AS division,hpd.visit AS DATE, 
card_amount_received AS amount,
card_check_modify AS card_check,
row_number() over (PARTITION BY card_amount_received ORDER BY id) AS seqnum FROM hospital_payment_data hpd WHERE store_mbrno = '234567' AND card_amount_received > 0) 
UNION ALL 
(
SELECT id, 
ncd. chart_num AS chart_num,
ncd. chart_name AS chart_name, 
division AS division, 
DATE_FORMAT(ncd.tranDate,'%Y-%m-%d') AS DATE, 
amount, card_check_result AS card_check,
row_number() over (PARTITION BY amount ORDER BY id) AS seqnum FROM noti_card_data ncd WHERE (mbrNo = '234567' OR mbrNo = '345678') AND (cmd ='승인'))) X
GROUP BY amount, seqnum
ORDER BY chart_name DESC

我想要结果

id  |    date     |         amount         |   result       | card_check
1     2020-06-23            10000                1               N
2     2020-06-24            20000                1               N
7     2020-06-25            30000                0               N
11     2020-06-26            30000                0               N

我想比较一下非信用卡数据的日期,直到主机支付数据的最近日期。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题