付款明细表
payment_detail_id| payment_id | payment_status | total | user_id | company_id
10001 | 10| 1 | 100 1 103
10002 | 11| 2 | 200 1 103
10003 | 12| 2 | 300 2 104
10004 | 13| 1 | 400 2 104
10005 | 14| 0 | 500 1 105
10006 | 15| 2 | 600 1 103
付款表
payment_id| payment_type|
10 | 1 |
11 | 1 |
12 | 1 |
13 | 1 |
14 | 0 |
15 | 0 |
如何从user_id
获取具有{{1}的payment_type
和1
的{{1}}的{{1}}?
目的是要发现他们已经进行了两种付款,对于已经付款两次的人,他们必须拥有payment_type
中的0
,但是如果
例如,如果Payment_Table
为payment_status
,而2
为user_id
,则输出必须为1
。
这个拥有company_id
的用户拥有103
100+200+600=900
和company_id
,并且对于这两个条件payment_Type
已成功完成0
的用户的1
中,即使之前付款失败
例如,(payment_type=1 and payment_type=0)
是payment_Status
的{{1}}是2
。
答案 0 :(得分:0)
SELECT
DISTINCT user_id
FROM
Payment_Detail_Table D
WHERE
EXISTS(
SELECT
*
FROM
Payment_Table P1
WHERE
P1.payment_id = D.payment_id
AND
P1.payment_type = 1
)
AND
EXISTS(
SELECT
*
FROM
Payment_Table P2
WHERE
P2.payment_id = D.payment_id
AND
P2.payment_type = 0
)
答案 1 :(得分:0)
这是您要寻找的吗?
<svg width='64px' height='64px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="uil-default"><rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect><rect x='46' y='35' width='8' height='30' rx='5' ry='5' fill='#666666' transform='rotate(0 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0s' repeatCount='indefinite'/></rect><rect x='46' y='35' width='8' height='30' rx='5' ry='5' fill='#666666' transform='rotate(36 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.1s' repeatCount='indefinite'/></rect><rect x='46' y='35' width='8' height='30' rx='5' ry='5' fill='#666666' transform='rotate(72 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.2s' repeatCount='indefinite'/></rect><rect x='46' y='35' width='8' height='30' rx='5' ry='5' fill='#666666' transform='rotate(108 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.3s' repeatCount='indefinite'/></rect><rect x='46' y='35' width='8' height='30' rx='5' ry='5' fill='#666666' transform='rotate(144 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.4s' repeatCount='indefinite'/></rect><rect x='46' y='35' width='8' height='30' rx='5' ry='5' fill='#666666' transform='rotate(180 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.5s' repeatCount='indefinite'/></rect><rect x='46' y='35' width='8' height='30' rx='5' ry='5' fill='#666666' transform='rotate(216 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.6s' repeatCount='indefinite'/></rect><rect x='46' y='35' width='8' height='30' rx='5' ry='5' fill='#666666' transform='rotate(252 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.7s' repeatCount='indefinite'/></rect><rect x='46' y='35' width='8' height='30' rx='5' ry='5' fill='#666666' transform='rotate(288 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.8s' repeatCount='indefinite'/></rect><rect x='46' y='35' width='8' height='30' rx='5' ry='5' fill='#666666' transform='rotate(324 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.9s' repeatCount='indefinite'/></rect></svg>