Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
Here is pics of Relationship and Pasenger_detail form and i wrote query to select seat_no but its not working properly. it is only showing all seats as per bus reserved id. but requirement were to show only those which are not yet selected. here is query
"Select seat_no.seat_no FROM Seat_No Where seat_no.seat_no <= (select br_info.Seats_Reserved from br_info where ((Br_info.br_id)=[forms]![pasenger_detail]![br_id]) AND (Seat_No.seat_no) NOT IN (SELECT Pasenger_Detail.Seat_No FROM Pasenger_Detail WHERE (((Pasenger_Detail.Group_ID)=[forms]![Pasenger_Detail]![Group_ID]) AND ((Pasenger_Detail.BR_ID)=[forms]![Pasenger_Detail]![BR_ID]))));"
SELECT S.Seat_No
FROM Seat_No AS S
WHERE S.Seat_No Not In
(
SELECT P.Seat_No
FROM BR_Info AS B INNER JOIN Pasenger_Detail AS P ON B.BR_ID = P.BR_ID
WHERE B.BR_ID = Forms!pasenger_detail!BR_ID
AND B.Group_ID = Forms!Pasenger_Detail!Group_ID
)
In the above query I am joining BR_Info and Passenger_Detail together. It is an INNER JOIN which means that the record has to exist in both BR_Info and Passenger_Detail in order to be considered. Then I am using Not In to get all the Seat_No that are not contained in the sub query.
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 6 years ago.
Improve this question
Im using Microsoft SQL Server 2008 and i wanted to dump something from the database.
Its holding over 585k users.
I wanted to ask how i can select a specific row in a column
Like the column is named "User_ResetKey" in the database US_HBS_MEMBERS the table would be US_UserInfo, im really a noob in that maybe someone can help me the row number would be 123921
I mean how i can fetch data what is in the row number 123921?
regards,
jamsb
via using
Row_number()
here you are ,
SELECT * FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY [User_ResetKey] ) AS rownumber,
*
FROM [US_HBS_MEMBERS].[dbo].[US_UserInfo]
) AS myTable
WHERE rownumber = 123921
supposed your schema is 'dbo'.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have some tables following
Room(CodeR, NameR)
Title(CodeT,NameT)
Member(ID,Name, Salary, Sex, CodeR, CodeT)
I want write the sql to select Roooms that member less than 5 and print all member of this room.
Please help me solve this problem
pls help me remove this topic. i can not ask any question.
select R.CodeR, NameR, m.Id, m.Name FROM
Room R INNER JOIN Member m on
R.CodeR = m.CodeR
WHERE R.CodeR in
(SELECT iM.CodeR FROM Member iM GROUP BY iM.CodeR HAVING COUNT(*) <5)
First of all pull all the rooms where no of members are less than 5
SELECT iM.CodeR FROM Member iM GROUP BY iM.CodeR HAVING COUNT(*) <5
Then pull out room and member information as required using above result.
select R.CodeR, NameR, m.Id, m.Name FROM
Room R INNER JOIN Member m on
R.CodeR = m.CodeR
WHERE R.CodeR in (X, Y, Z) //X, Y, Z will be replaced by subquery
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
if there are tables customer, order, and product then (online shopping)
1) all customers who have purchased more than one products in same order
2) top 10 customers who have spent most money
if there are doctors, patients and appointments then (hospital management)
1) all patients who have been diagnosed by more than one doctors
2) top 10 patients who have most appointments
if there are students, teachers and courses (school management system)
1) all students who have taken more than one course from same teacher
2) top 10 students with respect to scores
i'll do first one :
schema should be something like this customer--> orders-->products
1. select *,count(*) from customers c join order o on c.order_id=o.orders_id join products p on
p.product_id=c.product_id where count(*)>1 group by c.order_id,p.product_id
2.select top 10 from customers order by spent_money desc
SELECT patients, doctors FROM hospital_management GROUP BY patients,doctors HAVING COUNT(doctors) > 1
SELECT TOP 10 FROM hospital_management ORDER BY appointments DESC
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want a simple query to get some output. Records are
ID Count
215 1
215 1
215 1
215 1
Output must be
ID Count
215 4
SELECT ID, COUNT(*) AS Count
FROM tablename
GROUP BY ID
Very simple,
SELECT ID ,COUNT(*) AS CNT
FROM TABLE_NAME
GROUP BY ID
SELECT ID, sum(Count) AS Count
FROM tablename
GROUP BY ID
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can anyone help me with the script which will delete the data older than the particular date.
Thanks
delete from YOUR_TABLE where your_date_column < '2009-01-01';
This will delete rows from YOUR_TABLE where the date in your_date_column is older than January 1st, 2009. i.e. a date with 2008-12-31 would be deleted.
Delete data that is 30 days and older
DELETE FROM Table
WHERE DateColumn < GETDATE()- 30
You could use:
DELETE FROM tableName
where your_date_column < '2009-01-01';
but Keep in mind that the above is really
DELETE FROM tableName
where your_date_column < '2009-01-01 00:00:00';
Not
DELETE FROM tableName
where your_date_column < '2009-01-01 11:59';
This is pretty vague.
Do you mean like in SQL:
DELETE FROM myTable
WHERE dateColumn < '2007'
or an ORACLE version:
delete
from table_name
where trunc(table_name.date) > to_date('01/01/2009','mm/dd/yyyy')