| |

VerySource

 Forgot password?
 Register
Search
View: 2835|Reply: 14

How should this table be related? ? ?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-6 10:40:01
| Show all posts |Read mode
Form A: Drug Information (ypid ypname ...)
Form B: Diagnosis Information (zlid zlname ...)
A, B are the two major categories of medical expenses
Form C: Cost Information (Time Medical Number Expense Classification ypid or zlid ...)

Question: How to correlate ypid or zlid in table C with information such as ypname? (It is necessary to determine the expense category first, then the association. Can this be achieved? If you cannot just add the table C field, fix it)
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-1-6 11:45:01
| Show all posts
Theoretically, table A and table B should be foreign key tables of C, which means that table C should have two fields ypid and zlid associated with tables A and B, respectively.
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-1-6 11:57:01
| Show all posts
Sorry, said the other way.
In theory, C should be a foreign key table for tables A and B, that is to say, table C should have two fields ypid and zlid associated with tables A and B, respectively.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-7 12:51:01
| Show all posts
In this case, it is estimated that it is not easy to connect. Is there any other way to provide it? Thank youunkmass!
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-1-7 16:36:01
| Show all posts
If you can guarantee that the ypid of table A and the zlid content of table B do not overlap with each other, this can also be used, but there are disadvantages in the design.

select A.ypname, C. Expense classification, C. Time, C. Visit number from A, C where A.ypid = C. Expense classification and C. Expense classification in (select ypid from A);

select B.zlname, C. Expense classification, C. Time, C. Visit number from B, C where B.zlid = C. Expense classification and C. Expense classification in (select zlid from B);
Reply

Use magic Report

0

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 United States

Post time: 2020-1-19 16:09:01
| Show all posts
Depending on what database you use, I am familiar with oracle, and give you the implementation of oracle sql. The implementation mainly uses the decode function
select ... decode (expense classification, A, ypid, zlid), decode (expense classification, A, ypname, zlname)
To explain: the decode function is a conditional statement in SQL. If "Expense Classification" = "A", then ypid, otherwise zlid. Others are similar. Hope that helps. If the database is not using oracle, you can find similar functions implemented by your database.
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-21 23:27:02
| Show all posts
Add a field, add a problem and everything is solved. But it may be a bit more troublesome on the page.
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-1-22 06:09:01
| Show all posts
select A.ypname as expense name, C. expense classification, C. time, C. doctor number from A, C where A.ypid = C. expense classification and C. expense classification in (select ypid from A) union select B. zlname as expense name, C. expense classification, C. time, C. doctor number from B, C where B.zlid = C. expense classification and C. expense classification in (select zlid from B);
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-1-22 06:18:01
| Show all posts
MS SQL.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-17 14:30:01
| Show all posts
Two strong men
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list