|
hi,Jörgen Andersson
thank you for your help. the statement you posted seemed like a sqlsvr statement, I ran it on mysql and got a error:You have an error in your SQL syntax near "with.....".
I should run it on mysql.
in any case, I have got the correct answer of aim 1( I have write it in the top/first post), and plz help me with aim 2-4( It's still in trouble).
|
|
|
|
|
SELECT * FROM (SELECT COUNT(TCID) as C, TCID FROM service WHERE Qos = 1
and MONTH(EndTime) = 1
GROUP BY TCID) AS T
ORDER BY C DESC
This'll rank em for a month, I'll leave you to learn how to increment that month value to loop through for every one...
SELECT * FROM (SELECT COUNT(TCID) as count, TCID, Month FROM (SELECT month(endtime) as Month, tcid, serviceid FROM service
WHERE qos = 1
group by month(endTime),tcid, serviceid) AS T
GROUP BY month, tcid) AS S
order by month, count DESC
alternatly, this'll give you all of the months in the statement, I'll leave you to actually learn some SQL to refine it to get exactly what you want...
|
|
|
|
|
Thanks a lot!
I add filter statement( aim 1, without it the result will not be correct),like:
SELECT * FROM (SELECT COUNT(TCID) as count, TCID, Month FROM (
SELECT month(endtime) as Month, tcid, serviceid
FROM (SELECT MIN(Qos) qos, serviceid, id, TCID, EndTime from service
GROUP BY serviceid
)T1
WHERE qos = 1
group by month(endTime),tcid, serviceid
)As T
GROUP BY month, tcid) AS S
order by month, count DESC
and It got correct data:
count TCID Month
4 Andrew 1
3 Jacob 1
2 Tyler 1
2 Dylan 1
1 Daniel 1
4 Dylan 2
4 Jacob 2
4 Andrew 2
2 Tyler 2
1 Daniel 2
I think It is half of aim 2, thank you. please go on ,I think Top-2-in-January(rank) is Andrew/Jacob, Top-2-in-February(rank) is Andrew/Dylan/Jacob . So the result of aim2 should be 2 reocrders: Andrew/Jacob
modified 19-Apr-12 4:11am.
|
|
|
|
|
|
I have table(Tbl_A) in Server1 whenever DML(Insert/Update/Delete) operation happens in Tbl_A
it has to be automatically insert/Update/Delete into Table B,C(Tbl_B,Tbl_C) in different sever2.
'Whenever Table B,C Update/Delete/Insert record automatically record in Table A(Tbl_A).
I tried trigger but it does not help work for me.
Please advice me how to deal this scenario.
Thanks
Rao
Thanks & Regards
Rao
|
|
|
|
|
|
Thanks..
It won't do automatically only sync occasionally / manually.
I am looking for whenver DML operation happens.
Thanks & Regards
Rao
|
|
|
|
|
|
I have no better idea about relevant of database but your problem will be solve at w3school site because of there is well explain about database...I also daily visit that site for getting new information about html...
|
|
|
|
|
Have been working with and studying Microsoft SQL Server, SSRS and SSIS. I am reading about six books at the same time plus using them at work. I am close to interviewing for a Mid level job. I wish to hire a good T-SQL developer to put together study sheets which will include snipets of real world code in the major areas of TSQL such as stored procedures, funtions, loops, CASE and much more. I need to go in strong on the coding side but don't get much experience coding at work. Reading the books helps but its not like the real world.
ANY Suggestions.
|
|
|
|
|
It is an interesting approach, not sure what the response will be like! The way I always learn is to build, if there is an area where I feel deficient and work does not supply an opportunity to expand into that area I will build a project on my own time to explore the area.
While you are trying to short cut that process I don't think it can be done, someone can't feed you experience.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
As I ststed I am already reading 5 books and studying as hard as I can. I have no free time. I am only trying to get study sheets from a professional not take short cuts. I guess you suggest I stay in this underpaid paid possition that I can't even pay my rent with for another five years while I set up projects on my own to explore.
|
|
|
|
|
|
I was not denigrating the fact that you are trying, just the fact that experience is just that, experience and cannot be transferred, you can however learn from the experienced which is what you are trying to do.
Your problem is finding an experienced person with the spare time to teach and transfer that knowledge.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Get about ten years experience. Then you will know how to deal with the types of situations you will likely encounter.
|
|
|
|
|
hi ,i want to select name from all around tables
& i have near 25 tables such as : select name from pharmacy , hospital , theater ,etc...
all of them is linked with place table by id
this picture show sample of tables :
http://www.mediafire.com/?20rsb4q25kyj14w[^]
|
|
|
|
|
If there can be several names for a specific place :
SELECT
'Pharmarcy' AS Entity
,Pharmacy.Name AS Name
FROM
Pharmacy
INNER JOIN Place ON Place.Id = Pharmacy.PlaceId
UNION
SELECT
'Hospital' AS Entity
,Hospital.Name AS Name
FROM
Hospital
INNER JOIN Place ON Place.Id = Hospital.PlaceId
and so on...
If there can be only one name for a specific place:
SELECT
Pharmacy.Name AS PharmacyName
,Hospital.Name AS HospitalName
FROM
Place
INNER JOIN Pharmacy ON Place.Id = Pharmacy.PlaceId
INNER JOIN Hospital ON Place.Id = Hospital.PlaceId
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
i have used union
select mall.name from mall,places where mall.place_id=places.id UNION select hospital.name from hospital,places where hospital.place_id=places.id UNION select clinic.name from clinic,places where clinic.place_id=places.id UNION select shop.name from shop,places where shop.place_id=places.id
but it's very long i should select name from 25 table
can you use nested query i think it will solve the problem
|
|
|
|
|
Having a long query doesn't count as a problem. Why is it classified as such? Does it not work?
Bastard Programmer from Hell
|
|
|
|
|
when there is much commonality in the fields of a number of tables, it tells me the data should have been structured differently, using just one or two tables and one more field. You now have to pay for the bad decisions made earlier, by adding unproductive code everywhere.
|
|
|
|
|
Now I get nervous when a newbie wants me to download a file to my computer so I can help him! So I won,t be looking at your image!
You need to be clear as to what you want - in your message not some dodgy image. Ery you looking for the entity name from each of your tables or do you have a name field on each of your tables or (god forbid) you actually store a persons name in each table!
If they are linked by ID fields you should be able to build FKs and create a view of all the entity names in one table (possibly).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
don't download image just click on preview on medifie
|
|
|
|
|
As Luc pointed out, that is a lousy design, if you have address all over the place then you have made an error in your data design. You are going to have to live with the monster query or refactor your database (probably not reasonable solution)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Change your place table: add the column name . And then move your data to the correct place, and get rid of the name column in those other tables.
|
|
|
|
|
hi ,i want to select name from all around tables
& i have near 25 tables such as : select name from pharmacy , hospital , theater ,etc...
all of them is linked with place table by id
this picture show :
http://www.mediafire.com/?20rsb4q25kyj14w[^]
|
|
|
|