sort in unix, command not found error - sorting

I have one homework and I couldn't figure out what i am missing. I started with showing only department number 100. It shows department number 100 but also for every single line it says command not found.
This is my code:
awk '/:100:/ { print }' employees
The records in this file have 5 fields separated by colons (:). The fields are ssn, department, lastname, firstname and years_employed.
Use the employees file to create output where the employees are from DEPARTMENT 100 only, the number of years_employed has been increased by 1 year and the file is in sorted order.

Related

Oracle counting distinct rows using two columns merged as one

I have one table where each row has three columns. The first two columns are a prefix and a value. The third column is what I'm trying to get a distinct count for columns one/two.
Basically I'm trying to get to this.
Account
Totals
prefix & value1
101
prefix & value2
102
prefix & value3
103
I've tried a lot of different versions but I'm basically noodling around this.
select prefix||value as Account, count(distinct thirdcolumn) as Totals from Transactions
It sounds like you want
SELECT
prefix||value Account,
count(distinct thirdcolumn) Totals
FROM Transactions
GROUP BY prefix, value
The count(distinct thirdcolumn) says you want a count of the distinct values in the third column. The GROUP BY prefix, value says you want a row returned for each unique prefix/value combination and that the count applies to that combination.
Note that "thirdcolumn" is a placeholder for the name of your third column, not a magic keyword, since I didn't see the actual name in the post.
If you want the number of rows for each prefix/value pair then you can use:
SELECT prefix || value AS account,
COUNT(*) AS totals
FROM Transactions
GROUP BY prefix, value
You do not want to count the DISTINCT values for prefix/value as if you GROUP BY those values then different values for the pairs will be in different groups so the COUNT of DISTINCT prefix/value pairs would always be one.

How to correct the error, A table of multiple values was supplied where a single value was expected, when used with SELECTCOLUMNS in DAX

I have a table 1- Invoices report that looks like this:
Invoice Number
Customer Number
1
cus1
2
cus2
3
cus3
4
cus4
...
...
I want to make a column that has only the Customer Number.
I have used the following Expression:
Invoice Customers Number =
SELECTCOLUMNS(
'1- Invoices report',
"Customer Number",
'1- Invoices report'[Customer Number]
)
With this I am getting the error A table of multiple values was supplied where a single value was expected.
Any solution for this?
The result of SELECTCOLUMNS() is a table, not a column.
Make sure to use it as a calculated table, not a calculated column or measure:

Parsing and replacing columns in a file

INPUT:
I have an input file in which the first 10 characters of each line represent 2 fields - first 4 characters(field A) and the next 6 characters(field B). The file contains about 400K records.
I have a Mapping table which contains about 25M rows and looks like
Field A Field B SomeStringA SomeStringB
1628 836791 1234 783901
afgd ahutwe 1278 ashjkl
--------------------------------
--------------------------------
and so on.
Field A and Field B combined is the Primary Key for the table.
PROBLEM STATEMENT:
Replace:
Field A by SomeStringA
Field B by SomeStringB
in the input file. SomeStringA and SomeStringB are exactly the same width as Field A and B respectively.
Here's what I'm trying:
Approach 1:
Sort and Dump the mapping table into a file
spool dump_file
select * from mapping order by fieldA, fieldB;
spool off
exit;
Strip the input file and get the first 10 chars
cut -c1-10 input_file > input_file_stripped
Do something to find the lines that begin with the same string and then when they do - replace in the input_file with field 10-20 in the spooled file. - here's where I'm stuck.
Approach 2:
Take the input file and get the first 10 chars
cut -c1-10 input_file >input_file_stripped
Use sqlldr and load into a temp_table.
Select matching records from the mapping table and spool
spool matching_records
select m.* from mapping m, temp t where m.fieldA=t.fieldA and m.fieldB=t.fieldB;
spool off
exit;
Now how do I replace these in the original file ?
Given the high number of records to process, how can this be done and done fast ?
Notes:
Not a one time activity, has to be done daily so scale is important
The mapping table is unlikely to change
I've Python, shell script and Oracle database available. Any combination of these is fine.

Sum and relates tables DAX

I do have a table(1) containing the cost and the Project number, line number and item number and would like to get the cost summarized in another table(2) in a new column where im having the project number and project line also. The second table does not have the item number and does also contain budget figures on the more aggregate level. The two tables are linked on Keyz.
Table1
Item Cost PjNumb PjLine Keyz
------------------------------------------------------------
Q000001403 24,35 QP00032 11300102 QP0003211300102
Q000001405 24,35 QP00002 11100102 QP0000211100102
Q000001404 24,35 QP00003 11200202 QP0000311200202
Table2
PjNumb PjLine Budget keyz
------------------------------------------
HG00057 1910 190000 HG000571910
HG00057 111001 190000 HG00057111001
HG00057 111002 0 HG00057111002
Ive done the following formula in table2
=CALCULATE(SUM(Table1[Cost]);ALL(Table1[keyz]))
I'm not getting any value out in the new column in table2.
Hope some one are able to help me. The Pjnumb and PjLine in table1 is retreived from a third table, not shown here.
Kr
Jan

Where two or more values match condition?

I have been asked this question;
You list county names and the surnames of the representatives if the representatives in the counties have the same surname.
and I have the following tables;
***REPRESENTATIVE***
REPI SURNAME FIRSTNAME COUNTY CONS
---- ---------- ---------- ---------- ----
R100 Gorege Larry kent CON1
R101 shneebly john kent CON2
R102 shneebly steve kent CON3
I cant seem to figure out the correct way to ask Orical to display a surname that exists more then twice and the surnames are in the same country.
I know how to ask WHERE something = something, but that's doesn't ask what I want to know.
It sounds like you want to use the HAVING clause after doing a GROUP BY
SELECT surname, county, count(*)
FROM you_table
GROUP BY surname, county
HAVING count(*) > 1;
If you really mean "more than twice" as you wrote, none of the data you'd want HAVING count(*) > 2 but then none of your sample data would be returned.
In words, this SQL statement says
Group the data into buckets by surname and county. Each distinct combination of surname and county is a separate bucket.
Count the number of rows in each bucket
Return those buckets where there are at least two rows

Resources