I want to generate a report file based on the permissions granted to an Informix user for three different tables like follows:
USER Report
USER tbl1 tbl2 tbl3
A 1 0 0
B 1 0 0
C 0 1 1
D 0 1 1
In the above example 1 denotes user 'A' and 'B' has 'SELECT' permission on the 'tbl1' table and user 'C' and 'D' has 'SELECT' permission on the 'tbl2' and 'tbl3' tables.
I went through internet and got dbschema command. But its output is different then required.
Please guide me to generate this report.
Related
I have a query that does two queries. The first query looks at future events and what user is in that event from one table. The second query looks at the historical events and creates stats for the user in that event based off all the previous events that user was in from a second table.
I am having troubles joining the two queries. The goal of the join would be to join the second query to the first query based off the most recent stats for each user. The stat can't be newer than the date that the future event occured on. If that user hasn't been in any previous event it would just return null for the query 2 in the join.
Below is also an example table for the future query, a table for the historic query, and an ideal output of the join.
Future:
user
date
event code
event info
User 1
1/26/2023
5596
info_5596
User 2
1/26/2023
5586
info_5586
User 3
1/26/2023
5582
info_5582
User 1
1/20/2023
5492
info_5492
User 1
1/2/2023
5341
info_5341
User 2
1/2/2023
5333
info_5333
Historical:
user
date
stat 1
stat2
event code
event info
User 1
1/25/2023
10
52
4352
info_4352
User 2
1/25/2023
11
22
4332
info_4332
User 2
1/12/2023
2
45
4298
info_4298
User 3
1/12/2023
8
88
4111
info_4111
User 1
1/12/2023
7
67
4050
info_4050
User 3
1/2/2023
3
91
4000
info_4000
User 1
1/1/2023
6
15
3558
info_3558
Output of the JOIN:
user
date future
stat 1
stat2
event code future
event info future
User 1
1/26/2023
10
52
5596
info_5596
User 2
1/26/2023
11
22
5586
info_5586
User 3
1/26/2023
8
88
5582
info_5582
User 1
1/20/2023
7
67
5492
info_5492
User 1
1/2/2023
3
91
5341
info_5341
User 2
1/2/2023
null
null
5333
info_5333
I tried using a subquery in the join, but bigquery was saying that it is unsupported. Below is my code attempt. I have also tried using MAX() but it was not liking that to be used in the join as well
Another option I am thinking of is to join the two datasets before ever calculating the query 2 stats. Then filtering. I have a large query already written for both though, so I would prefer not to start over.
Select Distict
A.*
B.Stat1, B.Stat2
from future as A
Left Join historic as B
ON (
A.Date = (Select MAX(B.date) FROM historic as recent_historic WHERE recent_historic.user = A.user)
AND
A.user = B.user
)
ORDER BY A.date
Suppose I have the following dataset lookup:
ID T001 T002 T002 T004 T005
1 0 1 2 3 4
2 1 2 3 4 5
And I want to merge this onto my main dataset main:
proc sql;
create table main as
select a.*, b.*
from main as a
left join lookup as b on a.ID = b.ID;
quit;
However, this will merge the variables at "T001", "T002", "T003" etc.
I am trying to rename the variables with the merge/join, without having to manually rename each of them as there are 100's of these variables in the dataset. I am looking to get something like
ID V1 V2 V3 V4 V5
1 0 1 2 3 4
2 1 2 3 4 5
You can change the variables names dynamically with a simple macro function after the join
data have;
input ID T001 T002 T003 T004 T005;
datalines;
1 0 1 2 3 4
2 1 2 3 4 5
;
%macro rn;
%do i = 1 %to 5;
T00&i. = V&i.
%end;
%mend;
proc datasets lib=work nolist;
modify have;
rename %rn;
run;quit;
EDIT:
data have;
array t T001-T586 (586*100);
run;
%macro rn;
%do i=1 %to 586;
T%sysfunc(putn(&i., z3.)) = V&i.
%end;
%mend;
proc datasets lib=work nolist;
modify have;
rename %rn;
run;quit;
I'm working on part of a project about authorize and authenticate.so,but I've problem in the the same type of user with different permission.for example,
UserPermission Table
------------------------
UserId(int) //this is a AUTO INCREMENT primary key
UserBasicInformation(bool)
UserOperation(bool)
UserEntrance(bool)
UserExit(bool)
UserReport(bool)
AdminBasicInformation(bool)
AdminOperation(bool)
AdminSettings(bool)
UserPermissionId(int) // in this field I've kept key of users from UserDefs table
UserTitle(nvarchar)
UserDefs (brief)
--------------------------
UserId ///this is a AUTO INCREMENT primary key
UserType(int) //1,2
UserName(nvarchar) // admin,user
UserTitle(nvarchar) // alex,sara,....
UserId UserType UserName UserTitle
--------------------------------------------
1 1 Admin alex
2 1 Admin sara
3 2 user steve
4 2 user nicolas
this is UserPermision table that I populate for better understand.
UserId UserBasicInformation UserOperation UserEntrance UserExit
-----------------------------------------------------------------------------
1 0 0 0 0
2 0 0 0 0
3 1 1 1
UserReport AdminBasicInformation AdminOperation AdminSettings
-----------------------------------------------------------------------------
0 1 1 0
0 0 1 1
0 0 0 0
UserPermissionId UserTitle
-------------------------------
1 alex
1 sara
2 steve
if you take a look at userDefs table I have a two admins or two users but they are different permission in UserPermission table.but now,I don't know how to implement it.some people said me I use sessions what is your idea about it? in fact,I will read userpermission table.
I have a database (*.mdb), scheme of connection, that I use in my program:
TADOConnection -> TADOTable
DB has a table named Table1, which is connected by ADOTable. In Table1 there are fields A, B, C - floating point values. I need to sort the table by sums of these numbers.
For example:
Name A B C
------ --- --- ---
John 1 2 5
Nick 1 5 3
Qwert 1 5 2
Yuiop 2 3 1
I need to sort them, so the name, which A+B+C is bigger, would be first.
Sorted variant:
Name A B C
------ --- --- ---
Nick 1 5 3
John 1 2 5
Qwert 1 5 2
Yuiop 2 3 1
How to do this ?
While writing this, I understood what to do: I need a calculated field in the table, which is equal to A+B+C, and I must sort the table using it.
I do not have MS Access but with other Data Base Systems, I would use SQL to achieve this:
There are several SO answers along these lines for MS Access (try Microsoft Access - grand total adding multiple fields together)
So start with something like this:
Select Name, (A+B+C) as total, A, B, C
from table1
order by total desc
I'm trying to find a nice way to store word compositions of the following form:
exhaustcleaningsystem
exhaust cleaning system
exhaustcleaning system
exhaust cleaningsystem
The combinations are given by a default per case. Every word in a composition is stored as a unique row in table 'labels'.
labels
id value
--------------------------
1 exhaustcleaningsystem
2 exhaust
3 cleaning
4 system
5 exhaustcleaning
6 cleaningsystem
I thought about a new table called 'compositions':
compositions
id domain_id range
----------------------
1 1 2,3,4
2 1 5,4
etc...
But storing multiple separated values in a column isn't normalized design. Any ideas for that?
BTW: I'm using MySQL und ActiveRecord/Rails.
The design you propose is not even in first normal form, since range is not atomic
The schema I'd use here would be
compositions
id domain_id
-------------
1 1
2 1
compositions-content
composition_id rank label_id
------------------------------------------
1 1 2
1 2 3
1 3 4
2 1 5
2 2 4
with composition_id referencing an composition.id and label_id referencing label.id
The rank column is optional and should be here if and only if the range you define here is order-sensitive.
With this design, you have some referential integrity at DB level.
Well, this is as far as I can think of in terms of normalisation:
sets
id domain_id
--------------
1 1
2 1
etc...
compositions
id set_id label_id order
---------------------------
1 1 2 1
2 1 3 2
3 1 4 3
4 2 5 1
5 2 4 2
etc...