looks easy but difficult for me. the src/dest path of idx 1, 2, 3 has the same values.
so I need only 1 row for them.
idx Src_path dest_path code
1 /abc/aaa.txt /abc/dec_aaa.txt 01
2 /abc/aaa.txt /abc/dec_aaa.txt 02
3 /abc/aaa.txt /abc/dec_aaa.txt 03
4 /abc/aaa.txt /abc2/dec_aaa.txt 04
5 /abc/bbb.txt /abc2/dec_bbb.txt 01
6 /abc/ccc.txt /abc2/dec_ccc.txt 01
the result rows should be like below..
idx Src_path dest_path code
3 /abc/aaa.txt /abc/dec_aaa.txt 03
4 /abc/aaa.txt /abc2/dec_aaa.txt 04
5 /abc/bbb.txt /abc2/dec_bbb.txt 01
6 /abc/ccc.txt /abc2/dec_ccc.txt 01
bit.. difficult for me..
naw... kinda lazy you are, but thank god its friday.
SELECT MAX(idx), src_path, dest_path, MAX(code)
FROM yourtable
GROUP BY src_path, dest_path
should work out.
use SELECT DISTINCT Src_path
otherwise you can use
GROUP_CONCAT(Src_path) but then you will have to GROUP_BY
Related
I have this kind of data in my table
lineid
price €
01
100.00
02
200.00
01
10.34
01
311.12
01
14.33
02
36.44
03
89.70
04
11.33
and i would like my output to be like this
docid
lineid
price €
1
01
100
1
02
200.00
2
01
10.34
3
01
311.12
4
01
14.33
4
02
36.44
4
03
89.70
4
04
11.33
Its data for invoices and for every line that has lineid='01' it means that the info is for different invoice so i have to mark it with new documentID that i want you to help me create it with a command.
Its probably something easy but i am searching like a maniac here and i cant find the solution.
EDIT: Yes , it Is "increment docid each time lineid equals 01" what i want
You could use running counts using something like below (assuming this is MS SQL you are talking about)
SELECT ROW_NUMBER() over(partition by [LineId] order by [LineId]) as DocId,
[LineId],
[Price]
FROM [StackOverflow].[dbo].[RunningCount] order by [LineId]
Hi I have two tables here:
Transcript
Grade Student_number Course_number Semester Year
A 8 MATH2410 Fall 07
A 8 CS1310 Fall 07
B 8 CS3320 Spring 08
B 17 MATH2410 Fall 08
C 17 CS1310 Fall 08
A 8 CS3380 Fall 08
Student
Name Student_number Class Major
Smith 17 1 CS
Brown 8 2 CS
As you can see, they have a common Student_number. I want a table that looks like this:
Grade Student_number Course_number Semester Year Name
A 8 MATH2410 Fall 07 Brown
A 8 CS1310 Fall 07 Brown
B 8 CS3320 Spring 08 Brown
B 17 MATH2410 Fall 08 Smith
C 17 CS1310 Fall 08 Smith
A 8 CS3380 Fall 08 Brown
How do I do this?
I tried using insert and left join but neither worked. How do I achieve the third table? Thanks!
18 people have seen it, but none could figure out this question, so I did it myself with a bit of research.
SELECT STUDENT.Name, TRANSCRIPT.Grade, TRANSCRIPT.Student_number, TRANSCRIPT.Course_number, TRANSCRIPT.Semester, TRANSCRIPT.Year
FROM TRANSCRIPT
LEFT JOIN STUDENT
ON TRANSCRIPT.Student_number = STUDENT.Student_number
If your first two tables are still in use, maybe view is a better choice, and if Transcript.Student_number is must from Student, just use INNER JOIN.
create or replace view view_students_transcripts as SELECT t.*,s.name FROM Transcript t inner join Student s ON s.Student_number = t.Student_number;
I'm trying to bring data from two different columns into one query field. Example: Table1 [Field1] and [Field2]. I don't know if that's possible but in my Query I'm trying to bring the datas from these two Fields and show into one in Query. e.g.
|Table|
|DepartureDate1 | DepartureDate2|
| 15 Nov 2021 | 20 Nov 2021 |
|Query|
|DepartureDate1&2|
15 Nov 2021
20 Nov 2021
Thank you in advance.
Try using a UNION.
SELECT DepartureDate1 AS [DepartureDate] FROM Table1
UNION
SELECT DepartureDate2 AS [DepartureDate] FROM Table1
ID Year Month Price
001 1990 JAN 6
001 1990 FEB 8
...
001 1990 DEC 4
001 1991 JAN 7
...
001 2000 DEC 6
002 1990 JAN 7
...
Given a table formatted like the one above, how can you find the average yearly price for each item (of each year)? So for example, I'd like to have a new table that looks like:
ID Year Avg_price
001 1990 7
001 1991 12
...
002 1990 11
...
I've tried the following code:
SELECT ID, Year, AVG(Price)
FROM DATA
GROUP BY ID, Year
But end up getting 0 for each of the averages. The ordering seems to be working correctly though, so I'm not sure why this is. Any help would be greatly appreciated.
EDIT: It turns out there was nothing wrong with my SQL code at all. I guess the answer was simply a bug. Thanks for all your replies, everyone.
Your SQL looks fine to me (Checked with MS SQL).
SQL Fiddle Demo
Please doublecheck with MySQL. ;-)
I have a dataset like this:
Item Value Date Show
IT1 10 2012 01 01 1
IT1 9 2012 01 02 1
IT1 11 2012 01 03 1
IT2 8 2012 01 01 1
IT2 5 2012 01 02 1
IT2 3 2012 01 03 1
In a chart I have a filter which checks the Show value and leaves only rows where Show is 1. The problem is that instead of 2 items I see only 1, even though both of them have show = 1.
EDIT:
Filter expressions i tried:
=Fields!Show.Value = =1
=CInt(Fields!Show.Value) = =1
=CInt(Fields!Show.Value) = =CInt(1)
=CBool(Fields!Show.Value) = =CBool(1)
=CBool(Fields!Show.Value) = =CBool(True)
After using these expressions i get dataset like this:
Item Value Date Show
IT1 10 2012 01 01 1
I'm confused by your example - your dataset has 6 rows where show = 1 ?
Anyway, SSRS Filters are so obscure and generally best avoided, but this technique seems to be more reliable:
Filter Expression: =Fields!Show.Value = 1
Result Type: Boolean
Operator: =
Value: True