for eg: table emp (emp_id, ename, salary)
output: something like in Oracle: select emp_id, ename, salary, count(*) from emp
group by emp_id, ename, salary order by salary
using cqlsh
spark python option might be helpful..
thanks!
With changes to data model and using counters or aggregates (or even materialized views) you probably can solve that query. By using that data model and cqlsh you can't. Cassandra doesn't support group by.
If you already have Spark it makes sense and you can do it easily.
Related
I'm having much trouble with the Oracle Live SQL tutorials for the Oracle Apex Workspace. In particular, I'm stuck on Module 3: Inserting data because of the following:
The tutorial wants me to run the following code to add to the employees table:
insert into EMPLOYEES
(name, job, salary, deptno)
values
('Sam Smith','Programmer',
5000,
(select deptno
from departments
where name = 'Development'));
insert into EMPLOYEES
(name, job, salary, deptno)
values
('Mara Martin','Analyst',
6000,
(select deptno
from departments
where name = 'Finance'));
insert into EMPLOYEES
(name, job, salary, deptno)
values
('Yun Yates','Analyst',
5500,
(select deptno
from departments
where name = 'Development'));
However, when I attempt to run this code (which was copied and pasted from the tutorial into my Oracle Apex Workspace), I get the following error:
ORA-01427: single-row subquery returns more than one row ORA-06512: at "SYS.DBMS_SQL", line 1721
I checked my Objects aka tables to ensure that there were no tables with duplicate column names, however, I don't have any tables with any duplicates.
Can anyone help me with this? I'm quite new to both SQL and the Oracle Apex workspace.
This suggests that your departments has more than one row for certain names. You can determine which:
select name
from departments
group by name
having count(*) > 1;
There probably should not be duplicates. You probably accidentally loaded the data twice into the table, or something like that.
How to calculate Quantile 95 value, using SQL or PL/SQL?
With the SQL aggregate or analytic function PERCENTILE_DISC() (or perhaps PERCENTILE_CONT()). Google for your version of Oracle and the function name to find the Oracle documentation for these functions.
Here is how I can find the 95th percentile salary in the HR.EMPLOYEES table (HR is the standard HR schema that is installed with many Oracle databases):
select percentile_disc(0.95) within group (order by salary) as sal_95th_pctile
from hr.employees
;
SAL_95TH_PCTILE
---------------
13000
If instead I wanted to find the 95th percentile salary in each department, I would use the analytic version:
select percentile_disc(0.95) within group (order by salary)
over (partition by department_id) as sal_95th_pctile
from hr.employees
;
For the HR.EMPLOYEES table this makes little sense, since each department has only a few employees, so "95th percentile" is meaningless; but that's how you would do it when all "departments" had many values from which to compute the 95th percentile.
Get the names of the employees who are working on the project named “Office Security Project” and their responsibilities in the project
Give the qualification for the above query in:
1) conjunctive normal form, and
2) disjunctive normal form.
Consider the following relations
EMP (eNo, eName, title)
ASG (eNo, pNo, resp, dur)
PROJ (pNo, pName, budget, loc)
Query: Get the names of the employees who are working on the project named “Office Security Project” and their responsibilities in the project.
The query expressed in SQL is :
SELECT ENAME, RESP
FROM EMP, ASG, PROJ
WHERE EMP.ENO = ASG.ENO AND ASG.PNO = PROJ.PNO AND PNAME = “OFFICE SECURITY PROJECT’
To get data you should use select
SELECT employee,responsibility FROM table_name WHERE project_name='Office_Security_Project';
I am having problems implementing code to perform a couple calculations and setting column aliases.
Situation description:
The management wants to increase salary of all employees by 10%. Write a query to display empid, current salary, increased salary and incremented amount.
EmpId and Salary being existing columns in the table EmpDetails.
My Oracle SQL attempt:
SELECT
EmpId,
Salary AS 'Current Salary',
Salary*1.10 AS 'New Salary',
Salary*1.10-Salary AS 'Incremented Amount'
FROM EmpDetails
The output from my attempt is nothing. The interpreter doesn't support error messages and has issues displaying seemly valid code when it is incorrect for the problem for seemly any reason. This has left me confused while learning Oracle SQL syntax so the problem is likely the syntax in my attempt.
Is there way valid way to do this as a verbose select query like I attempted or maybe a simpler way for someone newer to SQL that uses multiple Alter/Update/Select commands?
enclose the alias with double quote.
SELECT
EmpId,
Salary AS "Current Salary",
Salary*1.10 AS "New Salary",
Salary*1.10-Salary AS "Incremented Amount"
FROM EmpDetails
I will explain the problem I am stuck on. I have a table named empl02 which contains Lastname, salary, and position for all the employees. I am asked to display last,name,salary, position for all employees making more money than the highest paid member of a certain 'position', we will call this position server. I cannot just do something simple like...
SQL> select Lastname,salary,position FROM empl02
2 WHERE
3 SAL > 125000;
Rather, it must be dynamic. I feel the logic is pretty simple I'm just not sure how to translate it into SQL. I am thinking something along the lines of
"SELECT Lastname,salary,position from empl02 where salary > MAX(SALARY) of position(server)" what is a way to translate this task to SQL?
You need to retrieve the "reference" salary as a sub-query:
select lastname, salary, position
from empl02
where salary > (select max(salary)
from empl02
where position = 'manager');