Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a table with the following values
and I need the output values as below.
Please help to arrive the code
It's not pretty, but this would work:
select *
from
(
select nams_contract_number, 1 as Sequence, 'Preqc' as DataType, act_preqc, est_preqc
from table
union all
select nams_contract_number, 2 as Sequence, 'abstractoin' as DataType, act_abstraction, est_abstraction
from table
union all
select nams_contract_number, 3 as Sequence, 'review' as DataType, act_review, est_review
from table
union all
select nams_contract_number, 4 as Sequence, 'postreview' as DataType, act_postreview, est_postreview
from table
) x
order by x.nams_contract_number, x.sequence
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
Can anyone help me with this? I have doubts about the below function; can I create a virtual column for this?
select as1.col,as1.col2,as1.col3 from
analytics.adjusted_sale_velocity
where
date(as1.created_datetime)=(
select
max(
date(created_datetime)
)
from
analytics.adjusted_sale_velocity
)
MySQL optimizer won't use an index once a column in the WHERE clause is wrapped with a function, date in your case.
Your query might be written a little different:
select as1.col,
as1.col2,
as1.col3
from adjusted_sale_velocity a
inner join ( select max(created_datetime) as created_datetime
from adjusted_sale_velocity
) as max_dt on left(a.created_datetime,10) = left(max_dt.created_datetime,10) ;
Try and let me know if it is faster.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have query for to get data following :
select a from REPLACE(M,',','')TABLE;
I want to get all the data from table along with M column content replce , with space.
You select from the table. What you select belongs in the SELECT clause:
SELECT t.*, REPLACE(m, ',', '') FROM mytable t;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
As the title suggests, trying to take the count or possibly distinct count of a column, we call it year, to count the number of a years for an individual or populated ID and place it another column in the same table. Here is an idea of what I have so far and we want to update the table. Thank you.
Join group table to updated table directly:
UPDATE outputtable O JOIN
(SELECT personID, COUNT(DISTINCT year) AS countYear
FROM outputtable GROUP BY personID) temp ON O.personID=temp.personID
SET O.N=temp.countYear
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am having a database with 2 columns employee and job.Job column contains character in each record.In that,I have to list the employees whose job is having last 3 characters as 'man'.I have to use only functions in SQL Query.
Use LIKE with wildcard:
SELECT *
FROM your_table
WHERE job_column_name LIKE '%man'
or using RIGHT
SELECT *
FROM your_table
WHERE RIGHT(job_column_name, 3) = 'man'
Answer For Question 4 is
SELECT *
FROM emp
WHERE SUBSTR(job,-3,3)='MAN';
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
There is a table called member_info and this table have 2 rows (member_id and sponsor_id)
table looks like :
member_id (1,2,3,4,5,6,7,8);
sponsor_id (,1,1,1,2,5,5,5);
Now i need to pick those member_id's who are not in sponsor_id like
member_id(3,4,6,7,8);
Any help Appreciated.
You can use the NOT IN function with a sub-query:
SELECT `member_id`
FROM `member_info`
WHERE `member_id` NOT IN (
SELECT DISTINCT(`member_id`) FROM `sponsor_info`
)
Subqueries introduced with the keyword NOT IN also return a list of zero or more values.
SELECT member_id
FROM member_inf
WHERE member_id NOT IN (
SELECT DISTINCT(member_id) FROM sponsor_info
)