SQL Count query - Assistance needed
Hello
Hoping someone can point me in the right direction. Here's the query I have so far. What I'm trying to do is to compare and add the names of the skills of individuals. My current query will count them, however, I need to take a step further where if the person has a name of "Spanish" skills can only which is counted and not their names other skills.
Current query:
WITH AS TBL1
(SELECT
TRIM (A.NWIE_ID) AS NWIE_ID,
A.AGENT_NM,
B.BUSINESS
Of
LIGHTHOUSE. IEX_AGENTS A JOIN
LIGHTHOUSE. TBL_GEN_MU_BUSINESS B
ON A.MU_ID = B.MU_ID
WHERE B.BUSINESS IN ('PL_LEGACY'));
TBL2 ACE
(SELECT
TRIM (C.USER_ID) AS USER_ID,
TRUNC (ASOF_DT, 'IW') AS WEEKBEGINNING,
CASE
WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL < = 2) THEN "basic".
WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL < = 7) THEN "moderate."
WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL < = 10) THEN 'complex '.
WHERE (SKILL_NM = "PLSCLegacySpanish") THEN 'Spanish '.
Another null
END AS SKILL_NM
THE LIGHTHOUSE. C CFG_PERSON_SKILL_HIST
)
SELECT
WEEKBEGINNING,
SKILL_NM,
COUNT (DISTINCT NWIE_ID) TOTAL_SKILLED
Of
TBL1,
TBL2
WHERE TBL1. NWIE_ID = TBL2. USER_ID
AND SKILL_NM NOT IN ('NULL %')
SKILL_NM GROUP, WEEKBEGINNING
ORDER OF WEEKBEGINNING, SKILL_NM
Create the Table data:
CREATE TABLE IEX_AGENTS
(
AGENT_NM VARCHAR2 (20).
NWIE_ID CHAR (8),
NUMBER OF MU_ID (5)
)
CREATE TABLE TBL_GEN_MU_BUSINESS
(
BUSINESS VARCHAR2 (100),
NUMBER OF MU_ID (5)
)
CREATE TABLE CFG_PERSON_SKILL_HIST
(
USER_ID VARCHAR2 (8).
DATE OF ASOF_DT,
SKILL_NM VARCHAR2 (64).
NUMBER OF SKILL_LEVEL (10)
)
INSERT INTO IEX_AGENTS (AGENT_NM, NWIE_ID, MU_ID) VALUES ("Marcelle, Athalie", "MARCELA1", 5)
INSERT INTO IEX_AGENTS (AGENT_NM, NWIE_ID, MU_ID) VALUES ('Lister, Laura", 'LISTERL3', 6)
INSERT INTO IEX_AGENTS (AGENT_NM, NWIE_ID, MU_ID) VALUES ("Purvis, Bradley", 'PURVIB1', 4)
INSERT INTO IEX_AGENTS (AGENT_NM, NWIE_ID, MU_ID) VALUES ("Cannon, Mark", "CANNON1", 4)
INSERT INTO TBL_GEN_MU_BUSINESS (BUSINESS, MU_ID) VALUES ('PL_LEGACY', 5)
INSERT INTO TBL_GEN_MU_BUSINESS (BUSINESS, MU_ID) VALUES ('PL_LEGACY', 6)
INSERT INTO TBL_GEN_MU_BUSINESS (BUSINESS, MU_ID) VALUES ('PL_LEGACY', 4)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('PURVIB1', 3/9/2014 12:00 ',' PLSCLegacy', 1).
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('MARCELIA1', 3/9/2014 12:00 ',' PLSCLegacy', 10)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('LISTERL3', 3/9/2014 12:00 ',' PLSCLegacy', 7)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('CANNON1', 3/9/2014 12:00 ',' PLSCLegacy', 7)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('MARCELIA1', 3/9/2014 12:00 ',' PLSCLegacySpanish', 3)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('LISTERL3', 3/9/2014 12:00 ',' PLSCLegacySpanish', 6)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('PURVIB1', 3/9/2014 12:00 ',' PLSCLegacySpanish', 2)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('PURVIB1', 3/19/2014 12:00 ',' PLSCLegacy', 10)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('LISTERL3', 3/19/2014 12:00 ',' PLSCLegacy', 2)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('MARCELIA1', 3/9/2014 12:00 ',' PLSCLegacy', 10)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('CANNON1', 3/19/2014 12:00 ',' PLSCLegacy', 7)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('CANNON1', 3/19/2014 12:00 ',' PLSCLegacySpanish', 7)
Results of the current query:
WEEKBEGINNING | SKILL_NM | TOTAL_SKILLED |
07/03/2014 12:00:00 AM | Foundational | 1 |
07/03/2014 12:00:00 AM | Complex | 1 |
07/03/2014 12:00:00 AM | Moderate | 2 |
07/03/2014 12:00:00 AM | Spanish | 3 |
14/03/2014 12:00:00 AM | Foundational | 1 |
14/03/2014 12:00:00 AM | Complex | 2 |
14/03/2014 12:00:00 AM | Moderate | 1 |
14/03/2014 12:00:00 AM | Spanish | 1 |
Desired results:
WEEKBEGINNING | SKILL_NM | TOTAL_SKILLED |
07/03/2014 12:00:00 AM | Foundational | 0 |
07/03/2014 12:00:00 AM | Complex | 0 |
07/03/2014 12:00:00 AM | Moderate | 1 |
07/03/2014 12:00:00 AM | Spanish | 3 |
14/03/2014 12:00:00 AM | Foundational | 1 |
14/03/2014 12:00:00 AM | Complex | 2 |
14/03/2014 12:00:00 AM | Moderate | 0 |
14/03/2014 12:00:00 AM | Spanish | 1 |
WITH ACE TBL1)
SELECT TRIM (A.NWIE_ID) AS NWIE_ID,
A.AGENT_NM,
B.BUSINESS
OF IEX_AGENTS HAS
JOIN THE
TBL_GEN_MU_BUSINESS B
ON A.MU_ID = B.MU_ID
WHERE B.BUSINESS IN ("PL_LEGACY")
),
(ACE TBL2)
SELECT USER_ID, TRIM (C.USER_ID)
TRUNC (ASOF_DT, 'IW') AS WEEKBEGINNING,
CASE
WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL<= 2)="" then="">=>
WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL<= 7)="" then ="">=>
WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL<= 10)="" then ="">=>
WHERE (SKILL_NM = "PLSCLegacySpanish") THEN 'Spanish '.
END AS SKILL_NM
OF CFG_PERSON_SKILL_HIST C
),
(AS TBL3)
SELECT USER_ID,
WEEKBEGINNING,
SKILL_NM,
COUNT)
SKILL_NM SEPARATE CASE
WHEN 'Spanish', 1
END
) HAS_SPANISH OVER (PARTITION BY USER_ID, WEEKBEGINNING)
FOR TBL2
)
SELECT WEEKBEGINNING,
SKILL_NM,
COUNT)
SEPARATE CASE
WHEN HAS_SPANISH = 0 THEN NWIE_ID
WHEN SKILL_NM = "Spanish" THEN NWIE_ID
END
) TOTAL_SKILLED
FROM TBL1;
TBL3
WHERE TBL1. NWIE_ID = TBL3. USER_ID
AND SKILL_NM NOT IN ('NULL %')
SKILL_NM GROUP,
WEEKBEGINNING
ORDER OF WEEKBEGINNING,
SKILL_NM
/
WEEKBEGINNING SKILL_NM TOTAL_SKILLED
---------------------- ------------ -------------
03/03/2014 12:00:00 am founders 0
03/03/2014 moderate from 12:00:00 am 0
03/03/2014 12:00:00 am 2 Spanish
17/03/2014 12:00:00 am complex 1
17/03/2014 12:00:00 am basic 1
17/03/2014 12:00:00 am Spanish 1
6 selected lines.
SQL >
SY.
Tags: Database
Similar Questions
-
SQL Dev 2.1 connected to a SQL Server query
I use developer SQL to query the oracle db and the results of the query, if I right click I get the following options;
Save grid under the report...
Single record view...
Number of lines...
Find/highlight...
Export data
However, when I do this on a SQL Server I get only the following:
Save the grid in the report...-c' is grayed out and cannot be used.
Single record view...
Number of lines...
Find/highlight...
I don't get the option to export, do anyone know why? or what I can do to get it?With SQL Developer 2.1.0 export feature has been removed for all with oracle database.
In section 2.1.1 export feature works again if you need to export to SQL server, you should switch to 2.1.1.
-
I need assistance of query SQL, a query to get the same without union clause
EmpNo, ename sum (sal) sum (deptno)
200-2000-10 Tom
201 3000 10 smith
Alfred 202 20 3000
40 8000 totalselect NVL(TO_CHAR(employee_id), 'Total'), max(last_name), sum(salary), sum(department_id) from employees group by rollup(employee_id), ()
-
assistance needed for a complex query
Hi guys
I need your help to write the sql query where I fill in null values when they are in the meantime, as you can see that the same data are for 2 ID... I am able to fill a value zero for id 101 as it's the last with the sql query below... but not able to do the same thing with when null values are between the two...
for id 102, if the value null line si la valeur null ligne date date is greater than or equal to the date of the previous row and fill in with the previous row null value... and if, as in the case of ord = '5' it is identical to the date of the next line, then I need to fill it with the next value of line WD...
Let me know if you need more information;
CREATE TABLE tt (id INT, int DSB, date the t1d, int WD)
INSERT INTO tt VALUES (101, '1','2011-12-20', '484')
INSERT INTO tt VALUES (101, '2','2011-02-12', '444')
INSERT INTO tt VALUES (101, '3','2011-02-12', '444')
INSERT INTO tt VALUES (101, '4','2011-02-14', NULL)INSERT INTO VALUES of tt (102, '1','2013-05-27', '544')
INSERT INTO VALUES of tt (102, '2','2013-06-02', '544')
INSERT INTO VALUES of tt (102, '3','2013-06-03', NULL)
INSERT INTO VALUES of tt (102, '4','2013-06-10', NULL)
INSERT INTO VALUES of tt (102, '5','2013-07-08', NULL)
INSERT INTO VALUES of tt (102, '6','2013-07-08', '690')
INSERT INTO VALUES of tt (102, '7','2013-07-10', '690')Select * from tt
SELECT nvl (WD, FINAL_WD) F_wd, * FROM
(
Select *,.
FINAL_WD = (SELECT b.wd
TT b
WHERE b.id = a.id
and b.ord + 1 = a.ord
and rownum = 1
ORDER BY b.ord desc)
TT one
WHERE a.wd is null
) DHello
Thanks for posting the sample data. Be sure to post the results desired from these data.
If ord and wd are numbers, then don't try to insert the strings (for example, '1') in these columns. It goes same for t1d, but even more. If t1d is a DATE, then insert only values, not DATE strings such as "2010-12-20'. TO_DATE allows to convert a string to a DATE, or use literals DATE. All your INSERT statements cause errors on my system because you are using the wrong type of data.
Maybe the analytical LAST_VALUE function can help you:
SELECT id, DSB
t1d
LAST_VALUE (WD IGNORE NULLS) over (PARTITION BY ID.
ORDER BY t1d
WD NULLS LAST
) AS new_wd
TT
ORDER BY id
t1d
;
-
Need of a just rows in table using SQL counter bearing
Oracle 11 g 2
RHEL 6.4
---------------
Given the following table data:
EMPLOYEE HIRE_DATE TERM_DATE DEPT
------------------ ----------------- ------------------ ---------
John Doe 01/01/13 101
Jane Smith 05/01/13 102
Bob Jones 102 02/04/13, 22/04/13
Jenny Boo 03/12/13 03/31/13 103
Joe Schmoe 24/03/13 102
Bill Max 23/04/13 103
Jill clay 24/04/13 103
Joe Boom 11/05/13 102
I want to return the number of employees who work for each month, as long as they were hired at anytime during the month and what if they ended this month (ie the month worries me). So I would expect
EMPLOYEE OF THE MONTH
Jan 2
3 Feb
5 March
April 6 (Jenny Boo ended)
May 6 (Jenny Boo and Bob Jones have been completed)
I know there are bright people out there who are SQL expert, but I'm not one of them. If there is a way to do this in SQL just I would like to see it.
Hello stew,.
Thanks for your reply. Looking at your SQL, where did you get the column "cnt"? I don't see that in any table, physical or virtual.
It is in the clause "unpivot" of the request he posted.
Create the table "emp1" and the data that Martin condition and then run the query that provided stew.
Works for me:
Select to_char (Lun, ' FMMonth, YYYY') month,
Sum (Sum (TO_NUMBER (CNT))) more employees (command per LUN)
de)
Select trunc (hire_date, 'MM') "1."
trunc (ADD_MONTHS(term_date,1), 'MM') '-1 '.
from emp1
) a
UNPIVOT (LUN for NTC in ("1", "-1"))
LUN group
order by Lun;
Header 1 Header 2 MONTH
EMPLOYEES January 2013 2 February 2013 3 March 2013 5 April 2013 6 May 2013 6 -
I have a database like this structure:
Table - lodges
LodgeID (PK)
Lodge
etc.
Table - scores
ScoreID (PK)
Score
CategoryID
LodgeID (FK)
I try to return the results in the form:
LodgeID, Lodge, category, number of Scores in this category, the average Score in this category
Thus, for example, if I had:
Lodges
LodgeID Lodge
1, lodge a
2, two lodge
scores
ScoreID, Score, CategoryID, LodgeID
1, 3, 101, 1
2, 5, 101, 1
3, 7, 101, 1
4, 10, 102, 2
2, 5, 20, 102
2, 6, 30, 102
7, 40, 102, 2
I will return:
1, box 1, 3, 5
2, Lodge 2, 4, 25
I tried things like:
SELECT COUNT (ScoreID) as scoreCount, AVG (Score) as Averagescore, Lodge OF scores_temp INNER JOIN lodges_temp ON scores_temp. LodgeID = lodges_temp. LodgeID
Without success. Pointers would be much appreciated.
Ignore that - just need to add a GROUP BY clause.
-
query SQL - COUNT (1)
Hi all
Under request, could someone explain COUNT (1) means?
Thanks in advance.INSERT INTO edr_class_by_speed_report_data ( site_id, site_lane_id, interval_start_date_time, vehicle_class, vehicle_speed, vehicle_count ) SELECT site_id, site_lane_id, interval_start_date_time, vehicle_class, speed, COUNT(1) FROM ( SELECT site_id, site_lane_id, (SELECT MAX(interval_start_date_time) FROM edr_rpt_tmp_grouping_table WHERE interval_start_date_time <= date_time) interval_start_date_time, vehicle_class, NVL( (SELECT MAX (min_speed) FROM edr_rpt_tmp_speed_ranges WHERE min_speed <= ROUND(vehicle_speed) ), 0 ) speed FROM edr_class_by_speed_veh_data WHERE edr_class_by_speed_veh_data.vehicle_error_count = 0 ) GROUP BY site_id, site_lane_id, interval_start_date_time, vehicle_class, speed;
It stands for count (*). See this AskTom discussion thread: [select Count (1) how it works | http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:1156151916789]
-
SQL query help needed in the Clause type
Hello
I'm currently learning Clause type. How can I write in the clause type to get the result below:
I have a table like this
DEPTNO ENAME
------- ------
20 SMITH
CELINE 10
BOND 20
ALLEN 30
WARD 30
20 JONES
30 MARTIN
30 BLAKE
10 CLARK
SCOTT 20
10 KING
30 TURNER
20 ADAMS
30 JAMES
20 FORD
10 MILLER
I want the output should look like this
DEPTNO ENAME
------ -----
CELINE 10, CLARK, KING, MILLER
20 JONES, ADAMS, BOND, FORD, SCOTT, SMITH
30 MARTIN, JAMES BLAKE, WARD, TURNER, ALLEN
Hear is the script I am currently working on.
with emp_group as
(
Select 20 deptno, ename 'SMITH' Union double all the
choose 10, 'CÉLINE' from dual union all
Select 20, "BOND" of all the double union
Select 30, 'ALLEN' from dual union all
Select 30, 'WARD' of all the double union
Select 20, "JONES' from dual union all
Select 30, 'MARTIN' from dual union all
Select 30, "BLAKE" from dual union all
choose 10, 'CLARK' from dual union all
Select 20, 'SCOTT' from dual union all
choose 10, 'KING' of the dual union all
Select 30, 'TURNER' from dual union all
Select 20, 'ADAMS' from dual union all
Select 30, 'JAMES' of the dual union all
Select 20, 'FORD' Union double all the
choose 10, 'MILLER' from dual
)
Select
DEPTNO
A1
of emp_group
model
ignore the nav
partition (deptno)
dimension (ROW_NUMBER() over (PARTITION BY deptno ORDER BY ename DESC) rn)
measures (ename, LPAD(' ', 100) A1)
rules)
A1 [rn > 0] = ename [cv ()],
A1 [0] = ename [cv ()]
)
order by deptno
;
your help is very appreciated.
Thank you in advance.
Try this.
Select
*
Of
(
with emp_group as
(
Select 20 deptno, ename 'SMITH' Union double all the
choose 10, 'CÉLINE' from dual union all
Select 20, "BOND" of all the double union
Select 30, 'ALLEN' from dual union all
Select 30, 'WARD' of all the double union
Select 20, "JONES' from dual union all
Select 30, 'MARTIN' from dual union all
Select 30, "BLAKE" from dual union all
choose 10, 'CLARK' from dual union all
Select 20, 'SCOTT' from dual union all
choose 10, 'KING' of the dual union all
Select 30, 'TURNER' from dual union all
Select 20, 'ADAMS' from dual union all
Select 30, 'JAMES' of the dual union all
Select 20, 'FORD' Union double all the
choose 10, 'MILLER' from dual
)
Select
DEPTNO
names
rn
of emp_group
model
ignore the nav
partition (deptno)
dimension of)
ROW_NUMBER() over (PARTITION BY deptno ORDER BY ename) rn
)
measures (ename, cast (null as names of varchar2 (40)))
rules
(
names [any] order by desc = ename [cv ()] rn | «, » || names [cv () + 1]
)
order by deptno
)
where rn = 1
Best regards, Andrei
-
Hello world
I need to display the SPER_STATUS_TEXT count as 0 if there is no data from query below. Could someone help me please
SQL > SELECT a.sper_status_text, COUNT (*)
2 from (SELECT sper.assettxt,
CASE 3
4. WHEN sper.sper_status_text = "assessment" said.
5 THEN
6 'confirmed assessment '.
7. WHEN sper.sper_status_text AS "update - rated %".
8 THEN
9 "update - rated up to."
10. WHEN sper.sper_status_text AS "update - % evaluated.
11. CAN
12 'update - rated down"
13 ELSE
14 "other responses.
15 END
16 sper_status_text
17 zzcus.zzcus_sper_data sper
18 WHERE sper.sper_dates = ' 20100801-20100831'
19 AND sper.customer_id = 'NATFINS. '
20 AND sper.task_inquiry_type = "Vendor Comparison"
21 AND sper.assettxt <>'! MAD
(22) a
23 GROUP BY a.sper_status_text
ORDER 24 (CASE
25. WHEN a.sper_status_text = "Said assessment" THEN 1
26. WHEN a.sper_status_text = "update - evaluated until ' THEN 2
27. WHEN a.sper_status_text = 'Update - rated down' THEN 3
28 4 SOMETHING ELSE
END 29);
Results:
SPER_STATUS_TEXT COUNT (*)
------------------------ ----------
Claims assessment 2
I need to display as below (if there no data I need to display the number as 0)
SPER_STATUS_TEXT COUNT (*)
------------------------ ----------
Claims assessment 2
Updated - evaluated up to 0
Updated - rated low 0
Other answers 0
Please adviceYou can get this. Using the TYPE clause.
SQL> SQL> CREATE TABLE ZZCUS_SPER_DATA1 2 ( 3 SPER_STATUS_TEXT VARCHAR2 (30) 4 ,TASK_INQUIRY_TYPE VARCHAR2 (100) 5 ); Table created. SQL> SQL> INSERT INTO ZZCUS_SPER_DATA1 2 VALUES ( 3 'Data Updated', 'Descriptive Data Challenge - Maturity date / Redemption date'); 1 row created. SQL> SQL> INSERT INTO ZZCUS_SPER_DATA1 2 VALUES ('Data Updated', 'Descriptive Data Challenge - Ticker / Local Code'); 1 row created. SQL> SQL> SELECT * 2 FROM ( SELECT A.SPER_STATUS_TEXT, COUNT (*) CNT 3 FROM (SELECT CASE 4 WHEN SPER.SPER_STATUS_TEXT = 'Data Confirmed' 5 THEN 6 'Data Item Confirmed' 7 WHEN SPER.SPER_STATUS_TEXT LIKE 'Data Updated' 8 THEN 9 'Data Item Updated' 10 ELSE 11 'Other Responses' 12 END 13 SPER_STATUS_TEXT 14 FROM ZZCUS_SPER_DATA1 SPER 15 WHERE 1 = 1 16 AND SPER.TASK_INQUIRY_TYPE LIKE 'Descriptive Data Challenge%') A 17 GROUP BY A.SPER_STATUS_TEXT 18 ORDER BY (CASE 19 WHEN A.SPER_STATUS_TEXT = 'Data Item Confirmed' THEN 1 20 WHEN A.SPER_STATUS_TEXT = 'Data Item Updated' THEN 2 21 WHEN A.SPER_STATUS_TEXT = 'Other Responses' THEN 3 22 ELSE 4 23 END)) 24 MODEL 25 DIMENSION BY (SPER_STATUS_TEXT) 26 MEASURES (CNT) 27 RULES 28 (CNT ['Data Item Confirmed'] = NVL (CNT[CV ()], 0), 29 CNT ['Data Item Updated'] = NVL (CNT[CV ()], 0), 30 CNT ['Other Responses'] = NVL (CNT[CV ()], 0)); SPER_STATUS_TEXT CNT ------------------- ---------- Data Item Updated 2 Other Responses 0 Data Item Confirmed 0 3 rows selected. SQL>
G.
-
SQL count (*) with Group of
Hello
I need help to fix this SQL.
Fields in the table are like that.
Basically I want the values of user_id, user_name, last time the logged-in user and total number of times the userID(PK) user_id user_name login_time(timestamp)
the above query is to give the result set with user_id, user_name, last time that the user logged on, but how can I include count (*) Group of user_id in the sql aboveselect distinct user_id , user_name, login_date from USER_LOGIN where login_date in (select max(login_date) from USER_LOGIN group by user_id)
the sql above does not work.select distinct user_id , user_name, login_date, count(*) from USER_LOGIN where login_date in (select max(login_date) from USER_LOGIN group by user_id) group by user_id
can you help me to get the number of records by user_id group.
Thank you
SKHello
Looks like you want something like this:
SELECT user_id , user_name , MAX (login_time) AS last_login_time , COUNT (*) AS total_rows FROM user_login GROUP BY user_id , user_name ;
This assumes that user_login is off standard (like him are often seen), such that every row of the same user_id will also have the same user_name.
I hope that this answers your question.
If not, post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data. -
GROUP OF + SQL COUNT + SUM
Hello
I have a table, it has 2 colunms, (name, number)
name number
B1 7
B1 7
B1 28
B1 28
B1 28
B2 7
B2 28
B3 7
. .
. .
.
.
I want to see below
number
name sum 7sum 28sum
5 2 3 B1
2 1 1 B2
B3...
.
.
.
.
.
Can you help me
THANK YOU VERY MUCH FOR HELPLike this?
SQL> ed Wrote file afiedt.buf 1 with t as (select 'B1' as name, 7 as num from dual union all 2 select 'B1', 7 from dual union all 3 select 'B1', 28 from dual union all 4 select 'B1', 28 from dual union all 5 select 'B1', 28 from dual union all 6 select 'B2', 7 from dual union all 7 select 'B2', 28 from dual union all 8 select 'B3', 7 from dual) 9 -- 10 -- end of test data - use query below 11 -- 12 select name 13 ,count(*) 14 ,sum(decode(num,7,1,0)) as sum7 15 ,sum(decode(num,28,1,0)) as sum28 16 from t 17 group by name 18* order by 1 SQL> / NA COUNT(*) SUM7 SUM28 -- ---------- ---------- ---------- B1 5 2 3 B2 2 1 1 B3 1 1 0
-
Hello
I need help to form a query. I have two tables Support_issues and Support_comments with the information below.
I want to create a query to view the account of the situation for the last 15 days until today.
Sample Input data support_issues: ISSUE_ID ISSUE_DESC CREATION_DATE STATUS 1 AAA 01/NOV/2011 Open 2 BBB 02/NOV/2011 Closed 3 CCC 02/NOV/2011 Open 4 DDD 03/NOV/2011 Reopened 5 EEE 03/NOV/2011 Reopened support_comments: COMMENT_ID ISSUE_ID COMMENT_DESC STATUS UPDATE_TIME 101 1 aaa Open 01/NOV/2011 102 2 bbb Open 02/NOV/2011 103 2 bbbbbb Closed 03/NOV/2011 104 2 bbbb11 Reopened 03/NOV/2011 105 3 ccc Open 02/NOV/2011 106 2 bbbbb Closed 03/NOV/2011 107 4 ddddd Open 03/Nov/2011 108 5 eeeee Open 03/NOV/2011 109 4 343434 Closed 06/NOV/2011 110 4 dfdf Reopened 07/NOV/2011 111 5 dfdfdf Closed 08/NOV/2011 112 5 udehjk Reopened 10/NOV/2011
For "Created" count of status must be taken Support_issues table, for others it must be taken from table Support_comments.Sample output: DATE Created Reopened Closed 28/OCT/2011 0 0 0 29/OCT/2011 0 0 0 30/OCT/2011 0 0 0 31/OCT/2011 0 0 0 01/NOV/2011 1 0 0 02/NOV/2011 2 0 0 03/NOV/2011 2 1 2 04/NOV/2011 0 0 0 05/NOV/2011 0 0 0 06/NOV/2011 0 0 1 07/NOV/2011 0 1 0 08/NOV/2011 0 0 1 09/NOV/2011 0 0 0 10/NOV/2011 0 1 0 11/NOV/2011 0 0 0
Please help me to form a query for this!
Thank you
MukeshHello
Try the following query
with t1 as ( select to_char(sysdate-level+1,'dd-mm-yyyy') as date_range from dual where level<16 connect by sysdate-16
Cannot test because I did not create, insert commands...
-
Problem with PL/SQL insert query
Hello to all the genius... Vikram im, Im new in the world of the apex and pl/sql... I need everything that you guys help... This is my first application user (for example)
name of the table - form
name of the column - f_no number, name varchar2, number of salary.
Apex page n - p1_f_no, p1_name, p1_sal
Now my problem is the query that is below works in the workshop of sql (insertion of data in the table in shape) and can be seen using the select query... but when I implement this in the apex... It shows - in all areas:
declare
v_no number (3);
v_Name varchar2 (20);
v_sal number (10);
Start
Insert in the form values (: v_no,: v_name,: v_sal);
end;
IM using this query in the Process button,
Thank you
-Best regards,.
VikramMahir M. Quluzade have already responded.
Published by: Gokhan Atil on 03.May.2011 12:45
-
Assistance needed with Custom Transaction
Hello
I don't know if this is possible or not, but I would be very grateful for any help anyone can offer.
I wish to have a couple of drop down fields in form following a table after you select a choice from the drop-down list fields, it uses the data selected in the fields in the form to run a query that will empty the existing table and insert new records. Although I intend to do it on more than one field, I just try on a unique fields for the moment.
I use a Cusatom Transaction, because I believe that this will allow me to enter SQL which will perform more than one task. My understanding of this is correct?
The following code attempts to remove all existing records in the table, then insert new records. However, an error pops up when I click the button to insert the record. It seems that the SQL do not remove and insert consecutively in the same custom transaction.
Is this possible, and if so, can anyone advise me how to do this. My current SQL code as part of the operation is: -.
REMOVE TempAspirationalRole.* FROM TempAspirationalRole;
INSERT INTO TempAspirationalRole
SELECT TblRoles.RoleProfile_ID, TblRoles.RoleName, TblCourses.CourseName, TblRoleCourses.Requirement
OF (TblRoles INNER JOIN TblRoleCourses ON TblRoles.RoleProfile_ID = TblRoleCourses.RoleProfile_ID) INNER JOIN TblCourses ON TblRoleCourses.CourseRef = TblCourses.CourseRef
WHERE (((TblRoles.RoleProfile_ID) = {AspirationalRoleID}));The above will work properly in MySQL if I replace the {AspirationalRoleID} for a real record doesn't.
Thanks for your time,
Gary
At the end of the day, but start with something simple...
http://www.php.NET/function.MySQL-query
start deleting Ceccaldi
function My_Delete(&$tNG) {}Get the current values of the form
$threadid = $tNG-> getColumnValue ('NbForumMessageID');$query = "DELETE FROM messagesubscribe WHERE the threadID = '". $threadid. » » » ;
$result = mysql_query ($query);
If (! $result) {}
$message = "invalid query: '." mysql_error(). « \n\n » ;
$message. = "query string: '." $query;
$message = nl2br ($message);
Die ($message);
}Repeat as needed for other mysql queries
}
end My_trigger -
sql Update query after matching with the string
I am trying to reach the query that updates a table column with the value of the other table, after that he finds an exact match.
So here's the table data and sample to create.
I'm writing a query that would update the value of column - codedesc (currently Null) of the table1 table: after it is a string of column - table code1 codedesc.create table code1 ( codeid number, codedesc varchar2(60) ); Insert into code1 values ( 1,'R1 CONTRACTS'); Insert into code1 values ( 2,'R2 CONTRACTS'); Insert into code1 values ( 3,'R3 CONTRACTS'); Insert into code1 values ( 4,'R5 CONTRACTS'); Insert into code1 values ( 5,'R9 CONTRACTS'); Insert into code1 values ( 6,'R10 CONTRACTS'); create table table1 ( tablekey number, prefix varchar2(25), codedesc varchar2(60) ); Insert into table1(tablekey,prefix) values (1,'1001PAC'); Insert into table1(tablekey,prefix) values (2,'1001MXT'); Insert into table1(tablekey,prefix) values (3,'1002PAE'); Insert into table1(tablekey,prefix) values (4,'1003PCS'); Insert into table1(tablekey,prefix) values (5,'1004BDX'); Insert into table1(tablekey,prefix) values (6,'1005PAC'); Insert into table1(tablekey,prefix) values (7,'1006PAC'); Insert into table1(tablekey,prefix) values (8,'1007LDR'); Insert into table1(tablekey,prefix) values (9,'1009LCR'); Insert into table1(tablekey,prefix) values (10,'1010LBR'); Insert into table1(tablekey,prefix) values (11,'ABCDEF');
The logic for the match is, - take - 2nd column of table-codedesc code value and get 2 characters. For example, when the string is - R1 CONTRACTS, the string will be 1. (Select substr ("R1 CONTRACTS, 2, 2) of the double). -Output will be 1.
Now,.
Look in table 1 for the 3rd position of the prefix that corresponds to the string returned by the query above. So, if the prefix is '1001PAC', it should look for 2 value of figures from the 3rd position. So, in this case it will be 01. Digitally 01 and 1 are equal, then the match is found for this line in the table1 table, so we will need to update the value of the column codedesc with the "contracts of R1.
tablekey, prefix codedesc ---------- ------------------------------------------------------------ 1 1001PAC R1 CONTRACTS -- Needs to be update with this value. 2 1001MXT R1 CONTRACTS 3 1002PAE R2 CONTRACTS ... 11 ABCDEF --Null ( No Need to update when no match found).
Appreciate your help.SQL> select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Release 10.2.0.4.0 - 64bit Production PL/SQL Release 10.2.0.4.0 - Production CORE 10.2.0.4.0 Production TNS for Linux: Version 10.2.0.4.0 - Production NLSRTL Version 10.2.0.4.0 - Production
Hello
You want to avoid TO_NUMBER, given that will cause an error if even a line has a number no (except space) in the wrong place.
Use RTRIM to remove extra spaces at the end of the match_key and LPAD to add '0', if necessary, at the beginning:MERGE INTO table1 dst USING ( SELECT LPAD ( RTRIM ( SUBSTR ( codedesc , 2 , 2 ) ) , 2 , '0' ) AS match_key , codedesc FROM code1 ) src ON (src.match_key = SUBSTR ( dst.prefix , 3 , 2 ) ) WHEN MATCHED THEN UPDATE SET dst.codedesc = src.codedesc ;
Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!
Maybe you are looking for
-
What do I need to uninstall Firefox4 Beta manually once the final version of FireFox4 get out?
Can I just update Firefox4 Beta at the last stable Firefox 4 (when released) the same way I update Firefox3.6 or what I have to uninstall manually to avoid having two browsers FireFox?
-
email address is already message prevents me to reinstall an e-mail address
the Mail.app doesn't let me not reinstall an existing e-mail address because it says it already exists. I deleted it, of course, to reinstall and clear up some smtp problem what she felt and how he disappeared from the app and won't let me reinstall
-
Satellite C655 Audio suddenly doesn't work, Win10
I left my computer slowed down recently and returned to find the sound was, you guessed it, does not. I checked my speakers: market and plugged in without them: nothing. I watched the Volume mixer and found that it was not record my programs made no
-
problems with wireless connection.i have hp Pavilion dv6700
I have a hp pavillion laptop with windows vista home premium dv6707. the wireless program is antheros. my router is netgear wnr1000. I don't have internet connection when the ethernet cable is PLUGGED. When I try to connect without cable. I turn on t
-
+ I have no sound on windows vista