Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
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
Improve this question
Using this query I get my data which I want.
select *
from tbl_project
join tbl_project_detail on tbl_project_detail.project_id = tbl_project.id
I need to know how I can use this SQL in Linq-to-SQL:
select SUM(pd.no_vacancy) as Number
from tbl_project p
join tbl_project_detail pd on pd.project_id = p.id
where p.id='1'
I also try it but it doesn't work.
var result = (from p in db.tbl_projects
join c in db.tbl_project_details on p.id equals c.project_id
where c.project_id == type
select new { c.no_vacancy }).Sum();
Please help me.. I am stuck :(
I think this might be help you:
from p in tbl_project
join pd in tbl_project_detail on project_id equals p.id
where p.id=1
select new
{
sum(pd => pd.no_vacancy)
};
At Last I Solve My Problem By Using This
var result = (from p in db.tbl_projects
join
c in db.tbl_project_details on p.id equals c.project_id
where c.project_id == type
select (int)c.no_vacancy ).Sum();
Thank You Everyone For Helping Me.. :)
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 3 years ago.
Improve this question
I am working with Yii2 and I need to use the Query Builder to convert the following raw SQL query where I am using a subquery in the inner join.
SELECT *
FROM class
INNER JOIN
(SELECT name, MAX(score) AS Maxscore
FROM class
GROUP BY name) topscore
ON class.name = topscore.name
AND class.score = topscore.maxscore;
You should show a bit of effort on your behalf as it is how it works here on SO, but as you are a new bee so i am adding an answer.
It is pretty straight forward see the Query builder guide, and you need to use the subquery in the following way
$subQuery = new \yii\db\Query();
$subQuery->select([new \yii\db\Expression('[[name]], MAX([[score]]) as Maxscore')])
->from('class')
->groupBy('[[name]]');
$query = new \yii\db\Query();
$query->select('*')
->from('class')
->innerJoin(['topscore'=>$subQuery])
->where(['=','class.[[name]]',new \yii\db\Expression('topscore.[[name]]')])
->andWhere(['=','class.[[score]]',new \yii\db\Expression('topscore.[[maxscore]]')])
->all();
Note: I didn't tested it thou but it should work correctly.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I have 3 tables (ativo, modelo, tipo) and I need get some columns of the tables (tipo and modelo).
Structure:
Ativo: id_ativo, name_ativo, fk_tipo_atv, fk_modelo_atv
Tipo: id_tipo, name_tipo
Modelo: id_modelo, name_modelo, fk_tipo_modelo
I need list "name - name_tipo - name_modelo"
Anyone can help me?
You haven't given us much to go on regarding what results you want, how the tables are linked and what you've tried but assuming that Ativo.fk_tipo_atv is a link to Tipo.id_tipo and Ativo.fk_modelo_atv is a link to Modelo.id_modelo:
SELECT a.name_ativo,t.name_tipo,m.name_modelo
FROM Ativo a
INNER JOIN Tipo t ON (a.fk_tipo_atv = t.id_tipo)
INNER JOIN Modelo m ON (a.fk_modelo_atv = m.id_modelo)
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'm using sugarCRM CE 6.5.14.
I would like to export leads history ( mail details) section. I googled but the details are/were not enough to complete my requirement.
Normal leads > export > not having this history section.
Here is the SQL Query that I used. It works for me.
SELECT l.first_name, l.last_name, l.id, group_concat(n.name), n.description
FROM leads AS l
inner join notes as n on l.id = n.parent_id
where l.deleted = 0 and n.deleted = 0
group by l.id
Hope this will help to some one like me.
There is no way of using the SugarCRM CE UI to export Email records. The closest you can get is to derive the URI index.php?module=Emails&entryPoint=export which will give you the data about an email record (e.g. subject, related to information, status). It won't provide the sender, recipient or email content.
That means you'll need to get into the database or use a GUI reporting tool like JasperReports.
A query that pulls all emails (meta-data and content) from the database would be
select
name,
to_addrs,
cc_addrs,
bcc_addrs,
description,
description_html,
parent_id,
parent_type
from emails
join emails_text on emails.id = emails_text.email_id;
/* where parent_id = '<your lead id>' */
You should know that the Lead History subpanel is populated two ways in regards to Emails. Emails can be directly related to a lead, i.e. parent_id = the lead guid. They can also show up there if the email address matches. This happens if an email is related to an Opportunity or a Contact, but the to_addrs or from_addrs contain an email address that matches an email address that is also on file with the Lead. The above query does not take this non-directly-related emails into consideration. For a query that'll help with that, I recommend you dig into include/utils.php and check out a function called get_unlinked_email_query().
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
Using mysql 4/5
I have 2 tables:
ROUTE
route_order (int)
zipcode
LOADS
load_id
pu_zipcode
do_zipcode
Goal:
select all rows from Loads where
pu_zipcode and do_zipcode are in Route AND
where the route_order pu_zipcode < route_order do_zipcode
I think this is what you are asking:
SELECT L.*
FROM Loads AS L
JOIN Route AS R1
ON R1.zipcode = L.PU_zipcode
JOIN Route AS R2
ON R2.zipcode = L.do_zipcode
WHERE R1.ROUTE_ORDER < R2.ROUTE_ORDER
Try this query
SELECT l.load_id, l.pu_zipcode, l.do_zipcode
FROM LOADS AS l, ROUTE AS r1, ROUTE AS r2
WHERE l.pu_zipcode=r1.zipcode
AND l.do_zipcode=r2.zipcode
AND r1.route_order<r2.route_order
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'm learning databases and I have a question: How can I list all the students that study in a specific school using joins?
My table is as follows:
X:schoolName(PK), SchoolAddress, SchoolTelephoneNumber
Y:schoolName(FK),StudentName,StudentNumber
How can i find out all the students name that study in 'London School' including there StudentNumber, SchoolAddress?
Try this:
SELECT
Students.StudentName,
Students.StudentNumber,
Schools.SchoolAddress
FROM
XSchools
INNER JOIN YStudents
ON Schools.schoolName = Students.schoolName
WHERE Schools.schoolName = 'London School'
SELECT
StudentName,
StudentNumber,
SchoolAddress
FROM
X
JOIN Y
WHERE Y.schoolName = 'London School'